steveblue / angular2-rollup

CLI for bundling Angular with Rollup and Closure Compiler
121 stars 18 forks source link

NGR ERROR SyntaxError: Unexpected token u in JSON at position 0 #26

Closed gkontokotsios closed 5 years ago

gkontokotsios commented 5 years ago

Hello.

I installed the latest version of angular-rollup and I created a new project using: $ ngr new my-app

I immediately tried building this project but I get this error:

$ ngr build prod rollup completed NGR ERROR SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse () at ReadFileContext.fs.readFile [as callback] (/usr/local/lib/node_modules/angular-rollup/src/build/prod.js:160:29) at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:235:13)

$ ngr -V 2.0.1

$ npm --version 6.4.1

$ node --version v10.12.0

Thanks!

steveblue commented 5 years ago

This is erroring on the part of the build that bundles rxjs. More specifically, the script is trying to read the rxjs package.json. Out of curiosity, which version of rxjs are you running currently and what is your environment @gkontokotsios Mac, Windows? Do you have rxjs properly installed in the node_modules directory?

gkontokotsios commented 5 years ago

Hi @steveblue. I am working on a Mac (Mojave v10.14.1). This issue can be reproduced without changing anything on a freshly generated project. $ ngr new my-app creates a project with a dependency to: "rxjs": "~6.3.3"

Also it takes care of running npm install and indeed rxjs is correctly installed in the node_modules directory.

And running ngr build prod always fails with the above issue.

steveblue commented 5 years ago

@gkontokotsios I am not able to reproduce with same configuration (node 10.12.0, angular-rollup 2.0.1). The issue indicates the content of a package.json file is being returned as undefined. Unexpected token u in JSON at position 0 is typically the error returned when the object passed into JSON.parse() is undefined.

Since I am not able to reproduce, the steps you would need to diagnose further:

Clone this repo. Run npm install Run npm link

This last command will link the repo to the global scope as if you ran npm i -g angular-rollup.

Find line 160 in prod.js and see what filePath and stdout return. Using console.log here will print to Terminal. --verbose flag with ngr build prod should prevent the log from clearing the Terminal.

gkontokotsios commented 5 years ago

Hi @steveblue, thank you for your support. I did exactly what you proposed and I get the following: filePath: node_modules/rxjs/websocket/package.json stdout: undefined

The package.json exists on this path: my-app/node_modules/rxjs/webSocket/package.json As you can see the webSocket is written with a capital S but the filePath above tries to access the directory with lowercase s. MacOS are running on a drive formatted as APFS Case-sensitive.

Where does the filePath get its value from?

gkontokotsios commented 5 years ago

@steveblue: The error is caused because in prod.js, line 188 the path to webSocket is with a lowercase s: node_modules/rxjs/webSocket/package.json

After changing this, the build worked on my system without further errors

steveblue commented 5 years ago

Merged into develop.

steveblue commented 5 years ago

TY @gkontokotsios for looking into it. Let me know how you are getting along with Closure Compiler in the Gitter!

gkontokotsios commented 5 years ago

@steveblue: You're welcome. Yeah sure I'll let you know!