mswjs / msw-storybook-addon

Mock API requests in Storybook with Mock Service Worker.
https://msw-sb.vercel.app
MIT License
410 stars 39 forks source link

SyntaxError: Unexpected token '?' error during CircleCI build process #48

Closed sklawren closed 3 years ago

sklawren commented 3 years ago

My project is Gatsby v3, with Storybook and the MSW Storybook plugin. I am only using MSW in Storybook and nowhere in the Gatsby site itself. Latest versions of all libraries.

In the CircleCI build, these errors appeared in the log during the build step. It didn't break the build (as far as I can tell), but I'm on a feature branch right now which doesn't attempt to deploy the entire Gatsby site. It just builds a single page Gatsby site which is enough for the Storybook to build and deploy to Chromatic.

At any rate, here are the errors. Not sure if they're anything to worry about considering the build finished successfully, but I felt like I should report them all the same.

> msw@0.35.0 postinstall /home/circleci/repo/node_modules/msw
> node -e "try{require('./config/scripts/postinstall')}catch(e){}"

/home/circleci/repo/node_modules/msw/node_modules/inquirer/lib/prompts/rawlist.js:126
      this.selected = this.selected ?? -1;
                                     ^

SyntaxError: Unexpected token '?'
    at wrapSafe (internal/modules/cjs/loader.js:1053:16)
    at Module._compile (internal/modules/cjs/loader.js:1101:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Function.promptModule.restoreDefaultPrompts (/home/circleci/repo/node_modules/msw/node_modules/inquirer/lib/inquirer.js:65:36)
    at Object.inquirer.createPromptModule (/home/circleci/repo/node_modules/msw/node_modules/inquirer/lib/inquirer.js:72:16)
    at Object.<anonymous> (/home/circleci/repo/node_modules/msw/node_modules/inquirer/lib/inquirer.js:84:28)
[MSW] Failed to automatically update the worker script:
Error: Command failed: node /home/circleci/repo/node_modules/msw/cli/index.js init /home/circleci/repo/.storybook/static
/home/circleci/repo/node_modules/msw/node_modules/inquirer/lib/prompts/rawlist.js:126
      this.selected = this.selected ?? -1;
                                     ^

SyntaxError: Unexpected token '?'
    at wrapSafe (internal/modules/cjs/loader.js:1053:16)
    at Module._compile (internal/modules/cjs/loader.js:1101:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Function.promptModule.restoreDefaultPrompts (/home/circleci/repo/node_modules/msw/node_modules/inquirer/lib/inquirer.js:65:36)
    at Object.inquirer.createPromptModule (/home/circleci/repo/node_modules/msw/node_modules/inquirer/lib/inquirer.js:72:16)
    at Object.<anonymous> (/home/circleci/repo/node_modules/msw/node_modules/inquirer/lib/inquirer.js:84:28)
yannbf commented 3 years ago

Hey @sklawren thanks a lot for reporting this issue! Although I think it will a bit difficult to investigate.

@kettanaito I believe this problem could be more related to the MSW dependency than to this addon. Can you confirm? Seems like a library is trying to use nullish coalescing however it's not supported because maybe the project's target is not high like ES11 ?

kettanaito commented 3 years ago

@yannbf, correct. The issue is in the inquirer fourth-party dependency installed alongside msw, which in turn is installed by this add-on. Please see https://github.com/mswjs/msw/issues/916 for the resolution.

TL;DR re-installing dependencies should help. If it doesn't pin the inquirer version to the one specified in the linked issue or newer.