schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

Module parse error in package.json #245

Closed CptAsgard closed 8 years ago

CptAsgard commented 8 years ago

After downloading p2 through npm like so:

npm i p2 -D

I get the following error when trying to build my project

npm run build

> untangled@1.0.0 build /home/frank/Projects/Untangled
> webpack

[webpack-validator] Config is valid.
Hash: 54f02b4b351fe1786b49
Version: webpack 1.13.1
Time: 1405ms
     Asset       Size  Chunks             Chunk Names
    app.js     406 kB       0  [emitted]  app
app.js.map     492 kB       0  [emitted]  app
index.html  177 bytes          [emitted]  
    + 62 hidden modules

ERROR in ./~/p2/package.json
Module parse failed: /home/frank/Projects/Untangled/node_modules/p2/package.json Unexpected token (2:9)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:9)
    at Parser.pp.raise (/home/frank/Projects/Untangled/node_modules/acorn/dist/acorn.js:923:13)
    at Parser.pp.unexpected (/home/frank/Projects/Untangled/node_modules/acorn/dist/acorn.js:1490:8)
    at Parser.pp.semicolon (/home/frank/Projects/Untangled/node_modules/acorn/dist/acorn.js:1469:73)
    at Parser.pp.parseExpressionStatement (/home/frank/Projects/Untangled/node_modules/acorn/dist/acorn.js:1994:8)
    at Parser.pp.parseStatement (/home/frank/Projects/Untangled/node_modules/acorn/dist/acorn.js:1772:188)
    at Parser.pp.parseBlock (/home/frank/Projects/Untangled/node_modules/acorn/dist/acorn.js:2009:21)
    at Parser.pp.parseStatement (/home/frank/Projects/Untangled/node_modules/acorn/dist/acorn.js:1753:19)
    at Parser.pp.parseTopLevel (/home/frank/Projects/Untangled/node_modules/acorn/dist/acorn.js:1666:21)
    at Parser.parse (/home/frank/Projects/Untangled/node_modules/acorn/dist/acorn.js:1632:17)
    at Object.parse (/home/frank/Projects/Untangled/node_modules/acorn/dist/acorn.js:885:44)
    at Parser.parse (/home/frank/Projects/Untangled/node_modules/webpack/lib/Parser.js:902:15)
    at DependenciesBlock.<anonymous> (/home/frank/Projects/Untangled/node_modules/webpack/lib/NormalModule.js:104:16)
    at DependenciesBlock.onModuleBuild (/home/frank/Projects/Untangled/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
    at nextLoader (/home/frank/Projects/Untangled/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
    at /home/frank/Projects/Untangled/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
    at Storage.provide (/home/frank/Projects/Untangled/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:52:20)
    at CachedInputFileSystem.readFile (/home/frank/Projects/Untangled/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:140:24)
    at DependenciesBlock.onLoadPitchDone (/home/frank/Projects/Untangled/node_modules/webpack-core/lib/NormalModuleMixin.js:255:7)
    at DependenciesBlock.loadPitch (/home/frank/Projects/Untangled/node_modules/webpack-core/lib/NormalModuleMixin.js:182:27)
    at DependenciesBlock.doBuild (/home/frank/Projects/Untangled/node_modules/webpack-core/lib/NormalModuleMixin.js:241:4)
    at DependenciesBlock.build (/home/frank/Projects/Untangled/node_modules/webpack/lib/NormalModule.js:84:14)
    at Compilation.buildModule (/home/frank/Projects/Untangled/node_modules/webpack/lib/Compilation.js:126:9)
    at /home/frank/Projects/Untangled/node_modules/webpack/lib/Compilation.js:309:10
    at /home/frank/Projects/Untangled/node_modules/webpack/lib/NormalModuleFactory.js:58:13
    at NormalModuleFactory.applyPluginsAsyncWaterfall (/home/frank/Projects/Untangled/node_modules/tapable/lib/Tapable.js:75:69)
    at onDoneResolving (/home/frank/Projects/Untangled/node_modules/webpack/lib/NormalModuleFactory.js:38:11)
    at onDoneResolving (/home/frank/Projects/Untangled/node_modules/webpack/lib/NormalModuleFactory.js:121:6)
    at /home/frank/Projects/Untangled/node_modules/webpack/lib/NormalModuleFactory.js:116:7
    at /home/frank/Projects/Untangled/node_modules/webpack/node_modules/async/lib/async.js:726:13
    at /home/frank/Projects/Untangled/node_modules/webpack/node_modules/async/lib/async.js:52:16
 @ ./~/p2/src/p2.js 46:36-62
Child html-webpack-plugin for "index.html":
        + 3 hidden modules

I haven't been able to trace this to any source. I've validated the json syntax of package.json, and I've checked if it's a valid package.json file, which it both is. I have also installed the json-loaader.

Any idea?

jtenner commented 8 years ago

If you are trying to load a json file, you need to modify your webpack loader to have a json loader.

https://github.com/webpack/json-loader

via

npm install --save-dev json-loader

Then try adding this line to your webpack.config.js

{
  module: {
    loaders: [
      { test: /\.json$/, loader: "json-loader" }
    ],
  }
}

It appears that a module depends on the package.json file which is a weird practice, but this should solve your problem.

CptAsgard commented 8 years ago

Alright, fair enough. I did install json-loader, but I didn't add it to the webpack config. It works now, thank you very much!

jtenner commented 8 years ago

Neat! Glad I could help.

Good luck with your project!

terkelg commented 7 years ago

I got this error too when using P2.js thorugh NPM in a webpack project. It helped to add the json-loader (Remember to add it to your webpack config)