[GH-ISSUE #17] Enable es6 import in Node.js #15

Closed
opened 2026-05-23 08:25:32 -06:00 by gitea-mirror · 7 comments
Owner

Originally created by @clibu on GitHub (Mar 4, 2021).
Original GitHub issue: https://github.com/appy-one/acebase/issues/17

I'm writing all my Node.js code using es6 import's however AceBase currently needs the following hack for import to work.

import pkg from 'acebase';
const { AceBase } = pkg;
Originally created by @clibu on GitHub (Mar 4, 2021). Original GitHub issue: https://github.com/appy-one/acebase/issues/17 I'm writing all my Node.js code using es6 import's however AceBase currently needs the following hack for import to work. ```` import pkg from 'acebase'; const { AceBase } = pkg; ````
Author
Owner

@appy-one commented on GitHub (Mar 4, 2021):

Why not just use

import { AceBase } from 'acebase';
<!-- gh-comment-id:790447028 --> @appy-one commented on GitHub (Mar 4, 2021): Why not just use ```js import { AceBase } from 'acebase'; ```
Author
Owner

@clibu commented on GitHub (Mar 4, 2021):

import { AceBase } from 'acebase';
         ^^^^^^^
SyntaxError: The requested module 'acebase' 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 'acebase';
const { AceBase } = pkg;
<!-- gh-comment-id:790448756 --> @clibu commented on GitHub (Mar 4, 2021): ```` import { AceBase } from 'acebase'; ^^^^^^^ SyntaxError: The requested module 'acebase' 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 'acebase'; const { AceBase } = pkg; ````
Author
Owner

@clibu commented on GitHub (Mar 4, 2021):

This is using "type": "module", in package.json

<!-- gh-comment-id:790451979 --> @clibu commented on GitHub (Mar 4, 2021): This is using ```"type": "module",``` in package.json
Author
Owner

@appy-one commented on GitHub (Mar 4, 2021):

I'm not able to reproduce?
If I set "type": "module" in my test package.json, I am able to use import { AceBase } from 'acebase'; without getting an error.
What node version are your using? I just tested with v14.15.4

<!-- gh-comment-id:790465237 --> @appy-one commented on GitHub (Mar 4, 2021): I'm not able to reproduce? If I set ```"type": "module"``` in my test package.json, I am able to use ```import { AceBase } from 'acebase';``` without getting an error. What node version are your using? I just tested with v14.15.4
Author
Owner

@appy-one commented on GitHub (Mar 4, 2021):

Apparently this is possible since Node v14.13.0, see this tweet, or this blog post about it: Node.js now supports named imports from CommonJS modules, but what does that mean?

<!-- gh-comment-id:790474818 --> @appy-one commented on GitHub (Mar 4, 2021): Apparently this is possible since Node v14.13.0, see [this tweet](https://twitter.com/MylesBorins/status/1311033983824793601), or this blog post about it: [Node.js now supports named imports from CommonJS modules, but what does that mean?](https://simonplend.com/node-js-now-supports-named-imports-from-commonjs-modules-but-what-does-that-mean/)
Author
Owner

@clibu commented on GitHub (Mar 4, 2021):

I am using 14.7.0 which works fine with es6 modules. I've just updated to 15.11.0 and import works now.

Whether you want to try and support older versions of Node is a question for you.😀

Did you notice my discussion post: https://github.com/appy-one/acebase/discussions/13

<!-- gh-comment-id:790894003 --> @clibu commented on GitHub (Mar 4, 2021): I am using 14.7.0 which works fine with es6 modules. I've just updated to 15.11.0 and import works now. Whether you want to try and support older versions of Node is a question for you.😀 Did you notice my discussion post: https://github.com/appy-one/acebase/discussions/13
Author
Owner

@appy-one commented on GitHub (Mar 4, 2021):

Sorry, didn't see the discussion earlier. Somehow the GitHub notification emails are not always getting through...

AceBase supports older Node versions, I haven't checked it but should at least be compatible back to version 7. If I switch to using ES modules, that would mean dropping support for older Node versions. And with the Node team already having fixed mixing CommonJS / ES modules, I'd say "don't fix it if it ain't broken"! 😄

<!-- gh-comment-id:790952019 --> @appy-one commented on GitHub (Mar 4, 2021): Sorry, didn't see the discussion earlier. Somehow the GitHub notification emails are not always getting through... AceBase supports older Node versions, I haven't checked it but should at least be compatible back to version 7. If I switch to using ES modules, that would mean dropping support for older Node versions. And with the Node team already having fixed mixing CommonJS / ES modules, I'd say "don't fix it if it ain't broken"! 😄
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/acebase#15
No description provided.