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

Error: To load an ES module, set "type": "module" in the package.json or use the .mjs extension #240

Closed
mastepanoski opened this issue Feb 24, 2023 · 10 comments · Fixed by #251
Labels
bug Something isn't working

Comments

@mastepanoski
Copy link

mastepanoski commented Feb 24, 2023

I upgraded to version 2.14.0 from 2.13.1 and when I build the project (Using nextjs+typescript), it triggers the following error:

info  - Collecting page data ..(node:26596) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/myuser/prj/node_modules/@textea/json-viewer/node_modules/@mui/material/Paper/index.js:1
export { default } from './Paper';
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1088:15)
    at Module._compile (node:internal/modules/cjs/loader:1123:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)

> Build error occurred

If I downgrade to 2.12.1 it works.

@pionxzh pionxzh added the bug Something isn't working label Feb 25, 2023
@pionxzh
Copy link
Collaborator

pionxzh commented Feb 27, 2023

You can use transpilePackages as a workaround first.

// next.config.js
const nextConfig = {
  reactStrictMode: true,
+ transpilePackages: ['@textea/json-viewer'],
}

@Tarasikee
Copy link

Having the same issue after migrating to Next13

@mastepanoski
Copy link
Author

You can use transpilePackages as a workaround first.

// next.config.js
const nextConfig = {
  reactStrictMode: true,
+ transpilePackages: ['@textea/json-viewer'],
}

This workaround worked.

@ghost
Copy link

ghost commented Mar 2, 2023

Having the same issue on Next v13. The workaround did NOT fix it.

@pionxzh
Copy link
Collaborator

pionxzh commented Mar 3, 2023

Having the same issue on Next v13. The workaround did NOT fix it.

Did you see a different error message?

@doomedramen
Copy link

Screenshot 2023-03-06 at 18 19 13
I am having the same issue

@doomedramen
Copy link

going to 2.12.5 was the solution for me

@pionxzh
Copy link
Collaborator

pionxzh commented Mar 6, 2023

This is accidentally introduced by #169. Downgrading to v2.13.1 should be ok.
I will rollback #169 tomorrow and look for an alternative for the solution of tree-shaking.

@pionxzh
Copy link
Collaborator

pionxzh commented Mar 7, 2023

v2.14.1 has been released. Let me know if you still see the same build error.

@mastepanoski
Copy link
Author

mastepanoski commented Mar 9, 2023

Since v2.14.1 it works without using the workaround. So it is fixed at least for me.

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

Successfully merging a pull request may close this issue.

4 participants