[Bug] package.json is missing a package "type": "module" description
See original GitHub issueVersion
5.3.1
Link to Minimal Reproduction
No response
Steps to Reproduce
Create app with nuxt bridge Build that app using nuxi build preview this app using nuxi preview
Current Behavior
Node throws error while trying import package as cjs module
Expected Behavior
Node import package as esm module
Environment
- OS: Windows 11
- Browser: Chrome 97
- Framework: Nuxt 2 Bridge
Any additional comments?
After building the application with nuxt bridge and running the application, Node tryes to import echarts and zrender as CJS modules, but there are ESM, as I can see. After I specified “type”: “module” in both packages, the problem has been solved.
Please specify module type in package.json
Issue Analytics
- State:
- Created 2 years ago
- Comments:10
Top Results From Across the Web
Why is 'type: module' in package.json file? - Stack Overflow
When you have "type": "module" in the package.json file, your source code should use import syntax. When you do not have, you should...
Read more >package.json - npm Docs
Description. This document is all you need to know about what's required in your package.json file. It must be actual JSON, not just...
Read more >Common Error Details - Snowpack
Node.js recently added support for a package.json “exports” entry that defines which files you can and cannot import from within a package.
Read more >cannot find module [Node npm Error Solved] - freeCodeCamp
To fix the error, you need to install the package that is absent in your project directory – npm install package-name or yarn...
Read more >package.json - Yarn
The description is just a string that helps people understand the purpose of the package. It can be used when searching for packages...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is a bug.
import * as echarts from 'echarts/core'
leads tobecause the content of
.js
files is determined by the value fortype
in the closest package.json.A proper fix for this requires a major release, as it affects the way current users import (or require) echarts. If you want to continue supporting cjs you need an exports map. A guide for releasing dual packages can be found here https://antfu.me/posts/publish-esm-and-cjs
Alternatively an
echarts-esm
package could be forked/released that no longer supports cjsOne possible workaround to fix this within 5.x would be to add files with explicit
.mjs
extension for all current js files that are imported anywhere or used as entry points.ps. zrender has a similar issue.
Cannot make echarts working with vitest because of this issue. Please considering fixing
package.json
according to this guide: https://github.com/sheremet-va/dual-packaging