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 #85

Closed
3 tasks done
MertHaddad opened this issue Jan 15, 2023 · 18 comments
Closed
3 tasks done

Module parse failed #85

MertHaddad opened this issue Jan 15, 2023 · 18 comments
Assignees

Comments

@MertHaddad
Copy link

Describe the bug

Uncaught Error: Module parse failed: Unexpected token (9057:38)
File was processed with these loaders:

  • ./node_modules/babel-loader/lib/index.js
    You may need an additional loader to handle the result of these loaders.

Reproduction

importing the module is enough.

System Info

W10 64 Chrome

Used Package Manager

npm

Validations

  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@kjbeethov
Copy link

Same issue

@ndom91
Copy link
Owner

ndom91 commented Jan 31, 2023

Can you give me some more details on your setup? Are you using "vanilla" react or a meta-framework like Next.js?

EDIT: For example, check out this working basic codesandbox example: https://codesandbox.io/s/basic-timezone-react-example-3dro2p

@volotovskyy
Copy link

Same issue

ERROR in ../node_modules/react-timezone-select/dist/esm/index.js 9:247489 Module parse failed: Unexpected token (9:247489) You may need an appropriate loader to handle this file type

Vanilla react 18.2.0

@ndom91
Copy link
Owner

ndom91 commented Mar 28, 2023

Hey there's a lot of updates related to bundling / published version.

Can you give the latest version on npm a shot?

@konstant-is
Copy link

konstant-is commented Mar 28, 2023

I get the same error with latest installed, using Nextjs though.

Update:

Fixed by adding: transpilePackages: ['react-timezone-select'] to next.config
Using Next 13.1.1

@ndom91
Copy link
Owner

ndom91 commented Mar 29, 2023

Looks like theres still an issue with using react-select with esm only projects.

See: JedWatson/react-select#5595

@ndom91
Copy link
Owner

ndom91 commented Mar 29, 2023

Published a new version with some changes, including making react-select a peer dependency, can you try [email protected]+.

i.e.

npm install react-select [email protected]

@codeforcesmeme
Copy link
Contributor

codeforcesmeme commented Mar 29, 2023

Is the error in this sandbox related to this one? It's an error in the dev server (react-scripts - when using v1.54+)

image

https://codesandbox.io/s/wonderful-franklin-15xbjq?file=/src/App.tsx

@ndom91
Copy link
Owner

ndom91 commented Mar 30, 2023

Is the error in this sandbox related to this one? It's an error in the dev server (react-scripts - when using v1.54+)

image

codesandbox.io/s/wonderful-franklin-15xbjq?file=/src/App.tsx

I believe this is something else based on one of the recent PRs, should be fixed in 1.5.6 / 2.0.0 though. Please give the latest release a try 🙏

@ndom91 ndom91 self-assigned this Mar 30, 2023
@nadnad
Copy link

nadnad commented Apr 20, 2023

Still seeing this with 2.1.0 when importing the TimezoneSelect component. The useTimezoneSelect hook import works fine though!

@a-type
Copy link

a-type commented Apr 28, 2023

I'm guessing it's because the TSC target for the library is ES2020, which is pretty recent all things considered. Many build tools assume libraries are compiled to older versions of ES.

https://github.com/ndom91/react-timezone-select/blob/main/tsconfig.json#L5

The solution in userland is probably to configure your bundler/builder to transpile the library (see NextJS transpilePackages) down to whatever version of ES it's using.

For the library author, maybe bump that target down to ES6 or at least something safer: https://www.typescriptlang.org/tsconfig#target

@ndom91
Copy link
Owner

ndom91 commented Apr 28, 2023

Yeah worth trying.. I've updated the tsconfig.json target to es6 in v2.1.1 👍

@ndom91
Copy link
Owner

ndom91 commented Apr 30, 2023

Let me know if that helped in any way 🙏

@milosDf
Copy link

milosDf commented Oct 17, 2023

Similar issue here:

image

I have:

"react-select": "^5.7.7", "react-timezone-select": "^2.1.0",

@ndom91
Copy link
Owner

ndom91 commented Dec 10, 2023

Does anyone still see this issue with 2.1.1+?

@danny-nguyen-lab49
Copy link

danny-nguyen-lab49 commented Dec 13, 2023

Yes I'm still experiencing this issue when running with nextjs. Seems though that its coming from the react-select dependency that is used by react-timezone-select if that helps. What's interesting is that in the actual code in my application, this is happening when i'm importing the useTimezoneSelect hook

import { useTimezoneSelect } from 'react-timezone-select'

"next": "^13.2.3"
"react-select": "^5.7.7",
"react-timezone-select": "2.1.2",

`error - ./node_modules/react-select/node_modules/@babel/runtime/helpers/esm/classCallCheck.js
Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' (1:0)
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 default function _classCallCheck(instance, Constructor) {
| if (!(instance instanceof Constructor)) {
| throw new TypeError("Cannot call a class as a function");

Import trace for requested module:
./node_modules/react-select/node_modules/@babel/runtime/helpers/esm/classCallCheck.js
./node_modules/react-select/dist/react-select.esm.js
./node_modules/react-timezone-select/dist/index.js
`

@ndom91
Copy link
Owner

ndom91 commented Dec 20, 2023

@danny-nguyen-lab49 can you give v3.1.0 a shot? I updated the react-select peer dependency to minimum version 5.7.3 where they apparently shipped a fix for ESM importing (https://github.com/JedWatson/react-select/releases/tag/[email protected]) and updated to ship only ESM builds of react-timezone-select

@ndom91
Copy link
Owner

ndom91 commented May 16, 2024

Haven't heard back here, should be working now so I'm going to close this.

If anyone still has an issue, feel free to open a new issue

@ndom91 ndom91 closed this as completed May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants