Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import packages which use optional chaining #9221

Closed
schneefux opened this issue Apr 30, 2021 · 2 comments
Closed

Cannot import packages which use optional chaining #9221

schneefux opened this issue Apr 30, 2021 · 2 comments

Comments

@schneefux
Copy link

Versions

  • nuxt: 2.15.4
  • node: 10.23.0 (codesandbox), 14, 15 and 16 (local)

Reproduction

https://codesandbox.io/s/confident-aryabhata-lbm28

Steps to reproduce

What is Expected?

The import should work the same as in plain NodeJS, i.e. require('vega-embed') works fine.

What is actually happening?

Webpack fails:

Module parse failed: Unexpected token (104:28)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| export function mergeDeep(dest, ...src) {
|     for (const s of src) {
>         deepMerge_(dest, s ?? {});
|     }
|     return dest;

Additional Details

vega-lite has recently changed their codebase to use the nullish assignment operator (vega/vega-lite#7207) and the transpiled files in build/src/, which are imported on import, contain them.

I think this comment explains the cause of the problem: #7722 (comment)
However, explicitely enabling the babel plugins as recommended does not solve the issue, as can be seen in the codesandbox.

This could be related to #7722, apparently only partially fixed by #8203.
Another issue with similar problems: #8893.
This issue is also potentially related: nuxt/typescript#248

@pi0
Copy link
Member

pi0 commented Apr 30, 2021

Hi @schneefux. Since webpack4 cannot undrestand syntax, you need to add vega-lite to build.transpile. See forked sandbox: https://codesandbox.io/s/xenodochial-lake-w07ge?file=/nuxt.config.js

export default {
  build: {
    transpile: ["vega-lite"]
  }
};

@schneefux
Copy link
Author

That's it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants