I was trying to upgrade our 1.10 project to 1.11 using the O365 CLI.
I simply used spfx project upgrade.
I got the following exception and the O365 CLI quit after that:
o365$ spfx project upgrade
readline.js:1086
throw err;
^
SyntaxError: Unexpected token in JSON at position 0
at JSON.parse (<anonymous>)
at manifestFiles.map (/usr/local/lib/node_modules/@pnp/office365-cli/dist/o365/spfx/commands/project/base-project-command.js:126:35)
Looking at the source code in this repo I noticed the expected encoding for the [webpart].manifest.json file is UTF-8, but somehow mine was UTF-8 with BOM. I changed the encoding of the file to UTF-8 and it started working after that.
Not sure if you'd call this a bug, but at least it's for those out there that run into the same error I did.
To fix this exception using VS Code:
spfx project upgradeTo reproduce this, change the encoding of the manifest.json file to UTF-8 with BOM. Then run spfx project upgrade. You should now have the same exception as mentioned above.
Either the result should be that the command works fine with different encodings, or it should detect that the encoding is wrong and tell me that I need to change the encoding to UTF-8.
The error mentioned above.
MacOS, running command from bash terminal inside VS Code.
Thanks for reporting! We haven't noticed it earlier, but we should handle it properly nevertheless. Good catch 👍
Hey @waldekmastykarz , I can pick this up 🙂 also sense checking here, we should apply the fix anywhere we read a utf8 encoded file and parse it correct?
Correct! Let's start with this one, and create separate issues for other locations to keep the overview
Makes sense, thank you
We have just released a preview version that fixes this issue. Once again thank you for reporting @MarkyDeParky 👏
Most helpful comment
Hey @waldekmastykarz , I can pick this up 🙂 also sense checking here, we should apply the fix anywhere we read a utf8 encoded file and parse it correct?