Node esm support
See original GitHub issueWhile I was testing to add an export map I found the following problem.
e.g. if we add this to minisearch
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"require": "./dist/umd/index.js",
"default": "./dist/es/index.js"
}
},
and then try to use it in node
// package.json
"type": "module"
// test.js
import MiniSearch from 'minisearch';
// execute
node test.js
we get the following error
node test.js
(node:65561) 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)
/www/testmini/node_modules/minisearch/dist/es/index.js:1436
export default MiniSearch;
^^^^^^
SyntaxError: Unexpected token 'export'
which is correct as we try to import the file dist/es/index.js
but the package minisearch
is define as a require
package… e.g. it has an implicit "type": "commonjs",
. e.g. all *.js
files are treated as common js
Solutions
- add
type: "module"
to package.json to minisearch so that*.js
files are treated as modules (and export the commonjs version as *.cjs files) - export the module version as
*.mjs
(which is kinda strange for a browser but still works)
What do you think?
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
ECMAScript modules | Node.js v19.3.0 Documentation
Node.js fully supports ECMAScript modules as they are currently specified and provides interoperability between them and its original module format, ...
Read more >What does it take to support Node.js ESM? – The Guild
ECMAScript modules, also known as ESM, is the official standard format to package JavaScript, and fortunately Node.js supports it .
Read more >Getting Started with (and Surviving) Node.js ESM
The Node.js ecosystem is shifting towards ESM. We examine what lies in store for application and library authors, learn some of challenges ...
Read more >Documentation - ECMAScript Modules in Node.js - TypeScript
For the last few years, Node.js has been working to support running ECMAScript modules (ESM). This has been a very difficult feature to...
Read more >Using ECMAScript modules (ESM) with Node.js
Using official ES module support. Let's start with the first (and official) way provided by Node.js io use ES modules in your Node...
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
you can probably support “all” the node versions if you want
something like this
and then I guess you would also have a separate umd for CDNs?
Released on NPM as part of
v5.0.0-beta2