search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

SyntaxError: Unexpected token in JSON at position 0

Asked by Julien
7 years ago.

Hi, we are trying DayPilot in our Ionic project and we are happy to see that you recently published a release supporting AOT compilation. Sadly when trying to compile DayPilot, we face an error:

[00:52:48] ngc started ...
Failed to read JSON file /var/lib/jenkins/jobs/.../workspace/src/node_modules/daypilot-pro-angular/daypilot-angular.min.metadata.json
[00:52:51] build prod failed: Unexpected token in JSON at position 0
[00:52:51] ionic-app-script task: "build"
[00:52:51] SyntaxError: Unexpected token in JSON at position 0
SyntaxError: Unexpected token  in JSON at position 0
at JSON.parse (<anonymous>)
at CompilerHost.readMetadata (/var/lib/jenkins/jobs/.../workspace/src/node_modules/@angular/compiler-cli/src/compiler_host.js:189:44)
at CompilerHost.getMetadataFor (/var/lib/jenkins/jobs/.../workspace/src/node_modules/@angular/compiler-cli/src/compiler_host.js:168:29)
at StaticSymbolResolver.getModuleMetadata (/var/lib/jenkins/jobs/.../workspace/src/node_modules/@angular/compiler/bundles/compiler.umd.js:26228:66)
at StaticSymbolResolver._createSymbolsOf (/var/lib/jenkins/jobs/.../workspace/src/node_modules/@angular/compiler/bundles/compiler.umd.js:26089:50)
at StaticSymbolResolver.getSymbolsOf (/var/lib/jenkins/jobs/.../workspace/src/node_modules/@angular/compiler/bundles/compiler.umd.js:26070:18)
at /var/lib/jenkins/jobs/.../workspace/src/node_modules/@angular/compiler/bundles/compiler.umd.js:25026:34
at Array.forEach (native)
at extractProgramSymbols (/var/lib/jenkins/jobs/.../workspace/src/node_modules/@angular/compiler/bundles/compiler.umd.js:25025:83)
at AotCompiler.compileAll (/var/lib/jenkins/jobs.../workspace/src/node_modules/@angular/compiler/bundles/compiler.umd.js:24671:51)

I'm not sure but it could some characters not correctly escaped that make failing JSON.parse().

We are using the build 8.3.2772

Comment posted by Dan Letecky [DayPilot]
7 years ago.

Can you check the daypilot-angular.min.metadata.json file to see what character is at position 0 (the first character in the file)? It should be '['.

The file uses UTF-8 with BOM (https://en.wikipedia.org/wiki/Byte_order_mark) so the first three bytes of the raw file are 0xEF, 0xBB, 0xBF. However, the BOM should be identified and handled transparently.

Answer posted by Julien
7 years ago.

It is definitively related to the use of BOM, If I open the file I clearly see the [ at first position but if the file is read through fs, the BOM is not stripped and the JSON.parse fails.

Comment posted by Dan Letecky [DayPilot]
7 years ago.

Thanks. The latest sandbox build (2778) now doesn't use BOM for daypilot-angular.min.metadata.json. Could you please give it a try?

npm install https://npm.daypilot.org/daypilot-pro-angular/trial/8.3.2778.tar.gz --save

Let me know if it doesn't help.

Comment posted by Julien
7 years ago.

I am going to create a ticket into Angular 2 I guess because they should support files with BOM. But this could take a while before being fixed.

Comment posted by Julien
7 years ago.

Awesome Dan, it works with the latest build.

Thanks a lot

Comment posted by Dan Letecky [DayPilot]
7 years ago.

Great, thanks for the update!

Comment posted by Dan Letecky [DayPilot]
7 years ago.

It turns out the BOM is illegal in JSON files:

https://tools.ietf.org/html/rfc7159#section-8.1

No need to file a bug with Angular 2.

Comment posted by Anonymous
7 years ago.

Ok,

Good to know. Thanks for you help. We will probably get a license soon. We are still checking that we can implement everything our client requires with DayPilot :-)

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.