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

Node fails to import ESM #1940

Closed
diachedelic opened this issue Sep 5, 2020 · 0 comments
Closed

Node fails to import ESM #1940

diachedelic opened this issue Sep 5, 2020 · 0 comments

Comments

@diachedelic
Copy link

Versions

  • @turf/helpers v6.2.0-alpha.2
  • Node.js v14.9.0
// ./foo.js
import { point } from "@turf/helpers";
console.log(point);

// ./package.json
{ "type": "module" }
$ node foo.js
import { point } from "@turf/helpers";
         ^^^^^
SyntaxError: The requested module '@turf/helpers' is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export.
For example:
import pkg from '@turf/helpers';
const { point } = pkg;

Replacing "@turf/helpers" with "@turf/helpers/dist/es/index.js" the same error message. Now, if I add "type": "module" to node_modules/@turf/helpers/package.json:

$ node foo.js 
[Function: point]

However, if I change the import back to "@turf/helpers":

$ node foo.js 
file:///Users/jamesdiacono/Code/monorepo/pkg/app/foo.js:1
import { point } from "@turf/helpers";
         ^^^^^
SyntaxError: The requested module '@turf/helpers' does not provide an export named 'point'
    at ModuleJob._instantiate (internal/modules/esm/module_job.js:98:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:137:5)
    at async Loader.import (internal/modules/esm/loader.js:165:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)

It appears that if package.json specifies "type": "module", then the "module" property is ignored! More discussion at nodejs/modules#432.

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

1 participant