question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] package.json is missing a package "type": "module" description

See original GitHub issue

Version

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:open
  • Created 2 years ago
  • Comments:10

github_iconTop GitHub Comments

7reactions
dominikgcommented, May 30, 2022

This is a bug. import * as echarts from 'echarts/core' leads to

export * from './lib/export/core.js';
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1033:15)
    at Module._compile (node:internal/modules/cjs/loader:1069:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)

because the content of .js files is determined by the value for type 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 cjs

One 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.

5reactions
kingyue737commented, Jun 10, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found