Open kdickerson opened 2 months ago
This is probably the same reason as for #284, and the way I tried to fix that broke even more things. If anyone can make a package.json that solves all problems, a pull request is very welcome.
Publishing NPM packages correctly is frustratingly hard. There is a recent article https://www.totaltypescript.com/how-to-create-an-npm-package on the topic. I have not read it yet, but it may give some hints on how to configure the project.
@kdickerson Temporary solution:
patch-package
npm install --save patch-package
Add patch file milsymbol+2.2.0.patch
in patches
directory (same directory where package.json
resides):
- package.json
- patches
| - milsymbol+2.2.0.patch
milsymbol+2.2.0.patch
:
diff --git a/node_modules/milsymbol/index.d.ts b/node_modules/milsymbol/index.d.ts
index d6c0451..5df96fb 100644
--- a/node_modules/milsymbol/index.d.ts
+++ b/node_modules/milsymbol/index.d.ts
@@ -221,3 +221,5 @@ export function getVersion(): string;
/** Sets the preferred standard. */
export function setStandard(standard: "2525" | "APP6"): boolean;
+
+export default { Symbol };
\ No newline at end of file
diff --git a/node_modules/milsymbol/package.json b/node_modules/milsymbol/package.json
index ea5e270..3c2602a 100644
--- a/node_modules/milsymbol/package.json
+++ b/node_modules/milsymbol/package.json
@@ -2,8 +2,15 @@
"name": "milsymbol",
"version": "2.2.0",
"description": "Milsymbol.js is a small library in pure javascript that creates symbols according to MIL-STD-2525 and APP6.",
- "main": "dist/milsymbol.js",
- "exports": "./index.js",
+ "type": "module",
+ "main": "./index.js",
+ "module": "./index.js",
+ "exports": {
+ ".": {
+ "import": "./index.js",
+ "types": "./index.d.ts"
+ }
+ },
"types": "index.d.ts",
"directories": {
"doc": "docs",
postinstall
script in package.json
:
// ...
"scripts": {
// ...
"postinstall": "npx patch-package --error-on-fail --error-on-warn"
}
I seem to be missing something. Without modifying
milsymbol
's package.json I can't seem to use it directly in a Node environment:Note in the information below that Node is complaining about
milsymbol
's package.json--not my example project which already defines"type": "module"
.package.json:
$ npm install
$ echo "import ms from 'milsymbol';" > index.js
SyntaxError: Cannot use import statement outside a module at wrapSafe (node:internal/modules/cjs/loader:1378:20) at Module._compile (node:internal/modules/cjs/loader:1428:41) at Module._extensions..js (node:internal/modules/cjs/loader:1548:10) at Module.load (node:internal/modules/cjs/loader:1288:32) at Module._load (node:internal/modules/cjs/loader:1104:12) at cjsLoader (node:internal/modules/esm/translators:346:17) at ModuleWrap. (node:internal/modules/esm/translators:286:7)
at ModuleJob.run (node:internal/modules/esm/module_job:234:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)