Skip to content
This repository was archived by the owner on Aug 20, 2018. It is now read-only.

making sure source is string before parsing #8

Merged
merged 1 commit into from Jul 26, 2015
Merged

making sure source is string before parsing #8

merged 1 commit into from Jul 26, 2015

Conversation

ghost
Copy link

@ghost ghost commented Jul 6, 2015

There is only one require in my sample app.

let pc = require("json-loader!./mock/welcome-page.json");

and I have been getting errors

ERROR in ./~/json-loader!./src/mock/welcome-page.json
Module build failed: SyntaxError: Unexpected token m
    at Object.parse (native)
    at Object.module.exports (/Users/ktan7/cxo-react/checkout/node_modules/json-loader/index.js:7:19)
 @ ./src/demo-app.jsx 21:13-60

@ghost
Copy link
Author

ghost commented Jul 6, 2015

Just checking the source type before parsing.

@mathieumg
Copy link

What does your JSON file look like?

@sloria
Copy link

sloria commented Jul 16, 2015

I am seeing this error as well.

storageAddons.json

{
    "box": {
        "fullName": "Box",
        "externalView": true
    },
    "dataverse": {
        "fullName": "Dataverse",
        "externalView": false
    },
    "dropbox": {
        "fullName": "Dropbox",
        "externalView": true
    },
    "figshare": {
        "fullName": "figshare",
        "externalView": true
    },
    "github": {
        "fullName": "GitHub",
        "externalView": true
    },
    "googledrive": {
        "fullName": "Google Drive",
        "externalView": true
    },
    "osfstorage": {
        "fullName": "OSF Storage",
        "externalView": false
    },
    "s3": {
        "fullName": "Amazon S3",
        "externalView": false
    }
}

webpack.common.config.js

module.exports = {
    //...
    module: {
        {test: /\.json$/, loader: 'json-loader'}
    }
}

Error message:

ERROR in ./~/json-loader!./website/static/storageAddons.json
Module build failed: SyntaxError: Unexpected token m
    at Object.parse (native)
    at Object.module.exports (<snip>/osf/node_modules/json-loader/index.js:7:19)
 @ ./website/static/js/filepage/index.js 7:20-54

@ghost
Copy link
Author

ghost commented Jul 24, 2015

thanks @sloria for the example. As you can see @mathieumg, there is a valid use case.

@mathieumg
Copy link

Odd that it doesn't already do this by default... Perhaps because it expects the json-loader to be chained with the file-loader? In any event, as a workaround you could consider using the json5-loader instead.

@sokra
Copy link
Member

sokra commented Jul 26, 2015

You applied the json-loader twice. Propably because you are using require("json-loader!./file.json") and json-loader in configuration. Use only one (prefer configuration).

sokra added a commit that referenced this pull request Jul 26, 2015
making sure source is string before parsing
@sokra sokra merged commit fa5464b into webpack-contrib:master Jul 26, 2015
@sokra
Copy link
Member

sokra commented Jul 26, 2015

But the PR changes don't hurt. But they won't fix your issues.

@sloria
Copy link

sloria commented Jul 27, 2015

Perhaps because it expects the json-loader to be chained with the file-loader? In any event, as a workaround you could consider using the json5-loader instead.

I tried both of these things:

    {test: /\.json$/, loaders: ['file', 'json']}
    {test: /\.json$/, loader: 'json5'}

But I still get the same error.

You applied the json-loader twice. Propably because you are using require("json-loader!./file.json") and json-loader in configuration.

I confirmed that I loaded json-loader in my configuration; not in the require call. I still get the error.

@mathieumg
Copy link

I think you have to reverse the order for the loaders.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants