Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6.4.14 regression: ESM imports no longer work #437

Closed
MattIPv4 opened this issue Apr 16, 2024 · 3 comments
Closed

6.4.14 regression: ESM imports no longer work #437

MattIPv4 opened this issue Apr 16, 2024 · 3 comments

Comments

@MattIPv4
Copy link
Contributor

MattIPv4 commented Apr 16, 2024

#422, but 6.4.14.

npm init -y
...

npm i mingo@6.4.13
...

node --input-type=module --eval "import { computeValue } from 'mingo/core'; console.log(computeValue);"
[Function: computeValue]

node --input-type=module --eval "import { Query } from 'mingo'; console.log(new Query({ test: 1 }));"  
Query {
  condition: { test: 1 },
  options: {
    idKey: '_id',
    scriptEnabled: true,
    useStrictMode: true,
    useGlobalContext: true,
    processingMode: 'CLONE_OFF',
    context: Context { operators: [Object] }
  },
  compiled: [ [Function (anonymous)] ]
}

npm i mingo@6.4.14
...

node --input-type=module --eval "import { computeValue } from 'mingo/core'; console.log(computeValue);"
file:///[snip]/[eval1]:1
import { computeValue } from 'mingo/core'; console.log(computeValue);
         ^^^^^^^^^^^^
SyntaxError: Named export 'computeValue' not found. The requested module 'mingo/core' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'mingo/core';
const { computeValue } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:134:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:217:5)
    at async ModuleLoader.eval (node:internal/modules/esm/loader:212:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Node.js v20.12.2

node --input-type=module --eval "import { Query } from 'mingo'; console.log(new Query({ test: 1 }));"
file:///[snip]/[eval1]:1
import { Query } from 'mingo'; console.log(new Query({ test: 1 }));
         ^^^^^
SyntaxError: Named export 'Query' not found. The requested module 'mingo' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'mingo';
const { Query } from 'mingo'; console.log(new Query({ test: 1 } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:134:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:217:5)
    at async ModuleLoader.eval (node:internal/modules/esm/loader:212:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Node.js v20.12.2
@kofrasa
Copy link
Owner

kofrasa commented Apr 16, 2024

Ah sorry about that. Switched to esbuild in the last update which should support ESM correctly but I may have gotten something wrong. Will deprecate this version for now and fix in next update.

@kofrasa
Copy link
Owner

kofrasa commented Apr 16, 2024

Ok, found the issue. NodeJS seem to translate ESM syntax to CommonJS so it uses the distribution under dist/cjs for which the output from esbuild is generated for only browsers when the platform option is not set. Setting that explicitly to node fixes the problem.

@MattIPv4
Copy link
Contributor Author

Looks to be working in 6.4.15, thank you!

@MattIPv4 MattIPv4 changed the title 6.4.14 regression: ESM imports no longer work #422 6.4.14 regression: ESM imports no longer work Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants