Cli-microsoft365: Bug report: spfx project upgrade causes JSON.parse exception

Created on 20 Jul 2020  ·  5Comments  ·  Source: pnp/cli-microsoft365

Description

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:

  • Open your project in VS Code
  • Open the manifest.json file
  • Look for the actual encoding in the bottom of the window (mine says UTF-8 with BOM)
  • Click it (the encoding)
  • Choose "Save with Encoding" from the Action menu in the top
  • Choose "UTF-8"
  • Re-run spfx project upgrade

Steps to reproduce

To 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.

Expected result

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.

Actual result

The error mentioned above.

Environment

MacOS, running command from bash terminal inside VS Code.

bug work in progress

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?

All 5 comments

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 👏

Was this page helpful?
0 / 5 - 0 ratings