Skip to content

?? Operator results in "Unexpected Token" err when used in package #9468

Closed
pass-culture/pass-culture-main
#1972
@arogozine

Description

@arogozine

Describe the bug

If you import a package that uses ?? operator in code, create react app will fail when debugging.

This issue seems to appear only when debugging with such a library. (npm run start)

It builds (npm run build) without errors. So the toolchain for start vs build is in question here.

The operator works fine if used directly - not in the imported library code.

Did you try recovering your dependencies?

Issues occurred with multiple CRAs even with reinstalling node modules.

Which terms did you search for in User Guide?

Null Coalescing Operator Create React App
There seems to be an issue about optional chaining.

Environment

Windows 10 10.0.17763
npm 6.14.5
node 14.4.0
Google Chrome was used to ensure async, let, const, classes, and ?? support.

Steps to reproduce

  1. Create a React App with TypeScript (Haven't tried without TS)
  2. Create NPM package (TS with target ESNext, module, commonjs, declaration) that uses the ?? operator
  3. Use package in your app.
  4. Run start script

Expected behavior

The application should compile and run successfully when started or when built..

Actual behavior

The application fails to compile due to the ?? in the library.

Failed to Compile,
Unexpected token
You may need an additional loader to handle the result of these loaders.

Reproducible demo

If needed I can brew something up. This was found in a work project.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions