Giter Site home page Giter Site logo

Enable es6 import in Node.js about acebase HOT 7 CLOSED

appy-one avatar appy-one commented on May 20, 2024
Enable es6 import in Node.js

from acebase.

Comments (7)

appy-one avatar appy-one commented on May 20, 2024

Why not just use

import { AceBase } from 'acebase';

from acebase.

clibu avatar clibu commented on May 20, 2024
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;

from acebase.

clibu avatar clibu commented on May 20, 2024

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

from acebase.

appy-one avatar appy-one commented on May 20, 2024

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

from acebase.

appy-one avatar appy-one commented on May 20, 2024

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?

from acebase.

clibu avatar clibu commented on May 20, 2024

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: #13

from acebase.

appy-one avatar appy-one commented on May 20, 2024

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"! 😄

from acebase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.