Please add {"type": "module"} to package.json
See original GitHub issueYou are publishing a module but not declaring it as such in package.json which makes it impossible to use
-> % cat test.mjs
import {} from "ip-address";
-> % node test.mjs
(node:71803) 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)
./node_modules/ip-address/dist/esm/ip-address.js:1
import { Address4 } from './lib/ipv4';
^^^^^^
SyntaxError: Cannot use import statement outside a module
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 Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Module._load (node:internal/modules/cjs/loader:827:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
Node.js v18.1.0
Currently to use this module we have to explicitly import as a CommonJS module:
import { createRequire } from "module";
const { Address4, Address6 } = createRequire(import.meta.url)("ip-address") as typeof import("ip-address");
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:9 (2 by maintainers)
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 >Modules: Packages | Node.js v19.3.0 Documentation
Within a package, the package.json "type" field defines how Node.js should interpret .js files. If a package.json file does ...
Read more >Add type = "module" in package.json to support nodejs in ...
To make it work, I had to add a main entry to the package.json as well as the "type": "module" (otherwise I just...
Read more >"module" in the package.json or use the .mjs extension 2022
Set type property in Package.json to module ... Now you can open the package.json file then add a new property called type and...
Read more >Creating Node.js modules - npm Docs
To create a package.json file, on the command line, in the root directory of your Node.js module, run npm init : · Provide...
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
I have the updated module published to npm as
@laverdet/beaugunderson-ip-address
. Our CI/CD conventions forbids git references so I put up there instead.Up