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

?. Module parse failed: Unexpected token #30

Closed
2 tasks done
sapkra opened this issue Oct 31, 2021 · 16 comments
Closed
2 tasks done

?. Module parse failed: Unexpected token #30

sapkra opened this issue Oct 31, 2021 · 16 comments
Labels
bug Something isn't working

Comments

@sapkra
Copy link

sapkra commented Oct 31, 2021

Checks

Version

0.6.5

Description

I only know the ?. syntax from TypeScript and I think that's the issue here.

ERROR in /node_modules/@splidejs/react-splide/dist/js/react-splide.esm.js 2449:16
Module parse failed: Unexpected token (2449:16)
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
|   }
|   go(control) {
>     this.splide?.go(control);
|   }
|   getSlides() {

Reproduction Link

No response

Steps to Reproduce

  1. Install current react-splide version
  2. Try to build it with webpack using es modules

Expected Behaviour

Should build without error

@sapkra sapkra added the bug Something isn't working label Oct 31, 2021
@NaotoshiFujita
Copy link
Collaborator

It's not a TypeScript specific feature.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

Webpack 5 supports the syntax.
webpack/webpack#10227

@sapkra
Copy link
Author

sapkra commented Nov 1, 2021

Mhh, okay interesting and good to know. But for more context: This error appeared in the currect storybook version 6.3.12 which theoretically uses webpack 5.

@NaotoshiFujita
Copy link
Collaborator

What do you mean "theoretically"? Storybook supports both webpack 4 and 5, and the default version is still 4.

@sapkra
Copy link
Author

sapkra commented Nov 1, 2021

Ohh ok sorry, I thought they switched to v5 in general. I'm sorry for the misunderstanding. At least we found the source of the problem.

@sapkra sapkra closed this as completed Nov 1, 2021
@NaotoshiFujita
Copy link
Collaborator

😎👍

@dimaninc2
Copy link

dimaninc2 commented Nov 2, 2021

I use the plugin with nextjs v11 which uses webpack 5, but i have the same error
node v12.19.0

@NaotoshiFujita
Copy link
Collaborator

If so, it's fatal for all nextjs users. You should report the bug to nextjs.

@dimaninc2
Copy link

dimaninc2 commented Nov 2, 2021

i've also installed @babel/plugin-proposal-optional-chaining and created .babelrc with the following contents:

{
  "presets": [
    "next/babel"
  ],
  "plugins": [
    "@babel/plugin-proposal-optional-chaining"
  ]
}

and this didn't help

@NaotoshiFujita
Copy link
Collaborator

It's one of the solution for webpack4 to recognize the optional chaining. Webpack 5 does not require it since it uses the latest acorn under the hood.

@jindada
Copy link

jindada commented Nov 2, 2021

Excuse me how to use react-splide with webpack4

{
  "plugins": [
    "@babel/plugin-proposal-optional-chaining"
  ]
}

this didn't help

@dimaninc2
Copy link

nextjs authors told me that "Next.js already supports optional chaining but node_modules are not compiled using Babel."

@NaotoshiFujita
Copy link
Collaborator

Ah, nextjs does not support transpiling node modules. It sounds very inconvenient.
vercel/next.js#706

Okay. I'll think about it.

@sapkra sapkra reopened this Nov 2, 2021
@NaotoshiFujita
Copy link
Collaborator

I transpiled the chaining syntax(^0.6.7).

@dimaninc2
Copy link

thanks, mate!

@NaotoshiFujita
Copy link
Collaborator

👍

@jogeshpi03
Copy link

Could someone help me to get the exact issue here.

./node_modules/@splidejs/react-splide/dist/js/react-splide.esm.js
Module parse failed: Unexpected token (3221:2)
You may need an appropriate loader to handle this file type.
|   children: children2,
|   className,
|   ...props
| }) => {
|   return /* @__PURE__ */React.createElement("div", {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants