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

Error when trying to require a JSON file #10

Closed
xavimb opened this issue Oct 2, 2015 · 3 comments
Closed

Error when trying to require a JSON file #10

xavimb opened this issue Oct 2, 2015 · 3 comments

Comments

@xavimb
Copy link

xavimb commented Oct 2, 2015

Webpack version: 0.12.2

I'm getting this error:

ERROR in dir/~/json-loader!dir/embedded/config.json
    Module build failed: SyntaxError: Unexpected token m
        at Object.parse (native)
        at Object.module.exports (dir/node_modules/json-loader/index.js:7:48)
     @ dir/embedded/includers/index.js 12:21-51

and in the includers/index.js I have this line:

var embeddedConfig = require("json!../config.json");

After checking, the problem is that the json-loader gets called two times, and the first one returns the expected outcome: "module.exports = {....}" but the second time it has "module.exports = {....}" as a source, so it tries to parse the string to JSON and then it fails because it's not a valid JSON.

Is anyone else getting the same error or did I do something wrong in the configuration?

@xavimb xavimb changed the title Error when trying to import the same file more than once Error when trying to require a JSON file Oct 2, 2015
@xavimb xavimb closed this as completed Oct 7, 2015
@Sridatta7
Copy link

I am also getting the same error

@transient-jonas
Copy link

Same error here :(

@MartinMuzatko
Copy link

Still having the error in latest json loader

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

No branches or pull requests

4 participants