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
Can't use default import with Babel #36
Comments
I put together an example with babel that seems to work with named imports: Faast.js doesn't have a default export; I'm unsure why that's a necessary use case given that the named import syntax seems to work fine with babel 7.4.4, per the example above. Maybe I'm missing something? |
Named imports work fine with Babel or esm. The reason I'm looking for the default import is because I'm trying to minimize the number of transpilers in my toolchain, and experimental modules work great for the vast majority of my The problem is with jest. Since it can't read One workaround is to edit my code and replace the default import with named imports only for testing (because Node can't use named imports with CommonJS modules). That kind of edit is not really acceptable, so I was wondering if there's a way to have the same "import faast" code work both with |
Let me take a crack at enabling |
This change helps future proof faast.js in anticipation of ES2015 module support coming to node.js. re #36
The |
Thanks for working on this. Might using Babel directly be a better option? |
You'll probably solve your problems if you use babel directly, but only if you use a named import for faast.js. The reason can be found here: http://2ality.com/2015/12/babel-commonjs.html#why-mark-transpiled-es6-modules-with-the-flag-esmodule:
The gist of it is, the reason However, faast.js is compiled into a es6 commonjs module, which does include the What I'd suggest for you is to use babel to introduce an explicit build step, then use Jest on the compiled .js outputs. This way Jest is not involved in invoking Babel and you have full control over how Babel is configured. As for using Node's experimental modules flag... well it's experimental. It's hard to live in the future when you have only today's tools available. |
Thanks for the module! I'm trying to use it via default imports with Babel (for interop within my project, and because Jest doesn't yet support
.esm
files natively).Boiling the problem down to Babel, here's an index.mjs including qs by comparison, whose default import works fine with both
--experimental-modules
and Babel:This works fine with
node --experimental-modules index.mjs
but fails like this with Babel:babel.config.js
is only this:I tried rebuilding with Babel 7 directly and the TypeScript preset, but the codebase uses outdated
namespace
s. Also triedtsc --target es5
and goterror TS1252: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Modules are automatically in strict mode.
.esModuleInterop: true
resulted in many TS2349 errors, a few TS7006, and one TS2351.The text was updated successfully, but these errors were encountered: