Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading of ng-package.json fails due to UTF-8 signature #87

Closed
Dastardl opened this issue Aug 3, 2017 · 6 comments · Fixed by #90
Closed

Loading of ng-package.json fails due to UTF-8 signature #87

Dastardl opened this issue Aug 3, 2017 · 6 comments · Fixed by #90

Comments

@Dastardl
Copy link

Dastardl commented Aug 3, 2017

Inside lib\steps\json.js the following line fails : resolve(JSON.parse(data)); whenever the file is saved as UTF-8 with a signature. This because fs.readFile returns a buffer instead of a string in that case.

This crashes creating the package whenever the ng-package.json was created by (for example) Visual Studio 2017. The workaround is saving this file as UTF-8 without signature every time it is modified, but this makes for a poor user experience :)

This was tested with Node v6.11.1

@dherges
Copy link
Contributor

dherges commented Aug 3, 2017

Hi @Dastardl,

what do you mean by "signature"? A byte order mask (BOM)?

I had a similar issue w/ webpack once webpack/enhanced-resolve#87 and then we (the people at my employer) decided that we just do not use BOMs and all is good :)

Let's keep the issue noticed but I'll priorize it low.

@Dastardl
Copy link
Author

Dastardl commented Aug 4, 2017

@dherges Correct, Visual studio just calls it "UTF-8 with signature", my mistake. Unfortunately this is the default format VS saves files in, so a good couple of people will be suprised when this package fails on even the most basic app (which is a bummer because it works really well!).

Would you consider using something like read-file? It basically just wraps the fs.readfile methods to remove the BOM when the encodigng is UTF-8.

What i forgot in my initial post is the actual error you get. I'll post it below for the avid googler.

BUILD ERROR
Unexpected token  in JSON at position 0
SyntaxError: Unexpected token  in JSON at position 0
    at Object.parse (native)
    at [your_path]\node_modules\ng-packagr\lib\steps\json.js:18:30
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:446:3)

@dherges
Copy link
Contributor

dherges commented Aug 4, 2017

Yes why not!

I just don't know when I have time for it ... I need to see. If you like to open a pull request, that's also good!

@dherges
Copy link
Contributor

dherges commented Aug 4, 2017

@Dastardl Can you review the changes in #90? That'll be good!

dherges added a commit that referenced this issue Aug 4, 2017
dherges added a commit that referenced this issue Aug 6, 2017
dherges added a commit that referenced this issue Aug 7, 2017
@Dastardl
Copy link
Author

Dastardl commented Aug 7, 2017

@dherges Just tested it with the lastest version and it is working like a charm!

@github-actions
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

This action has been performed automatically by a bot.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging a pull request may close this issue.

2 participants