Problem with load an ES module in the package.json
Opened this issue · 4 comments
Hi @UrielCh and @bnjunge, Currently I am developing my project using the proxmox-api package. I think this project contributed to my project. However, I have a warning here.
[1] (node:8232) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
[1] (Use `node --trace-warnings ...` to show where the warning was created)
[1] C:\Users\user\project\node_modules\proxmox-api\dist\esm\index.js:16
[1] export { proxmoxApi as default } from './constructor.js';
[1] ^^^^^^
[1]
[1] SyntaxError: Unexpected token 'export'
[1] at internalCompileFunction (node:internal/vm:73:18)
[1] at wrapSafe (node:internal/modules/cjs/loader:1178:20)
[1] at Module._compile (node:internal/modules/cjs/loader:1220:27)
[1] at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
[1] at Module.load (node:internal/modules/cjs/loader:1119:32)
[1] at Module._load (node:internal/modules/cjs/loader:960:12)
[1] at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
[1] at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
[1]
[1] Node.js v18.16.1
[1] [nodemon] app crashed - waiting for file changes before starting...
It is not complicated to solve. I added this in the package.json
file and then solved it. I wonder if can I merge this into your project. Or is there any alternative way around it? Thanks
{
"name": "proxmox-api",
"type": "module",
"version": "1.0.2",
...
}
I will double check that. pushing module compatible with ESM and commonJS, use to cause some issues.
Okay, I got it
In some cases you need to modify package.json to use it as an ESM or normal CommonJS,
for using as ESM you will use :
import proxmoxApi from 'proxmox-api'
and to use it as CommonJS you wil use it as :
const proxmoxApi = require('proxmox-api').proxmoxApi;
it works perfectly!
Hi,
I'm experiencing issues with CommonJS/ESM that are only apparent when using TypeScript.
I seldom use the require syntax.
I need to conduct some tests to ensure that PR #23 does not have any side effects on CommonJS TypeScript projects.
Please excuse my delayed response time, as I am currently without housing.