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

ESM Error #20

Closed
rajat12a opened this issue May 8, 2021 · 3 comments
Closed

ESM Error #20

rajat12a opened this issue May 8, 2021 · 3 comments

Comments

@rajat12a
Copy link

rajat12a commented May 8, 2021

node: 14.16.1
p-timeout: 5.0.0

After upgrading from version 4 to 5, getting this error

Error: Must use import to load ES Module: /app/available_modules/1620488012000/p-timeout/index.js
require() of ES modules is not supported.
require() of /app/available_modules/1620488012000/p-timeout/index.js from /app/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /app/available_modules/1620488012000/p-timeout/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /app/available_modules/1620488012000/p-timeout/package.json.

Since the project is using require instead of import, but after adding import statement in commonJS files

import pTimeout from 'p-timeout'
^^^^^^

SyntaxError: Cannot use import statement outside a module

converting the whole project to type: module in package.json will require all the files to be converted

So is there any other way to import the new version or should stick I for version 4 only, also what about future fixes which gets pushed on version 5?

@sindresorhus
Copy link
Owner

Please read the release notes. It explains everything and what options you have.

@konrad-garus
Copy link

Which release notes?

@papb
Copy link
Contributor

papb commented Jun 4, 2021

@konrad-garus This one

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

4 participants