-
Notifications
You must be signed in to change notification settings - Fork 456
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
Invalid es6 code generated when binding to module typed as function #2456
Comments
microsoft/TypeScript#2719 |
It might be related, but this issue is about the import semantics, not the export semantics. It could be interpreted as Here's one of many issues about it in the rollup repo: rollup/rollup#670 |
Webpack relies on this behavior for tree shaking too. |
This is currently what we have: import * as MyModule from "my-module";
MyModule(); I am a bit confused, is not Edit: sorry, I am a bit dumb here, is not what we generated correct here? |
Default import: import MyModule from 'my-module'; Namespace object (or "whole module", if you will) import * as MyModule from 'my-module'; |
This is causing me troubles right now, as I'm trying to use Rollup to bundle my code before deploying with firebase functions (related to #2127). But Rollup is throwing a namespace error when using the library
Is my only option right now to fork bs-express and use @glennsl's workaround? |
@splodingsocks are you sure you need to use rollup? webpack should work, unless you have very specific needs that only rollup can solve. |
Oh, I've never used Webpack for bundling libraries that expose functions before @glennsl. Firebase functions work by looking for the exports from the index.js file and hosting those as publicly accessible functions. I can certainly look into doing that with Webpack, though. I imagine it's possible? |
I have no reason to believe it behaves any differently than rollup in this regard, but I also haven't tried it so I don't know. You might also be able to use the commonjs rollup plugin to work around this. |
@glennsl why did you close this? |
Bob doesn't consider it a bug, and I no longer care. I think he was going to create a new issue for default import support. |
I've just hit this one as well. I think one of the entries in the interop cheatsheet is relevant:
With this one I'm getting the following output, which works with Babel: import * as myModule from 'my-module';
myModule.default(); But the problem with both this method and the one described in the issue description is, users of these bindings won't be able to use How about something like this for ES6 modules: import myDefault, * as myModule from 'my-module'; |
Hey guys don't think this should be closed. I'm also having issues. Trying some bindings for So for now I have for example:
That generates
Spent some good time to get into this issue and find the @glennsl 's workaround. |
@guilhermedecampo moved to #2677 For people who are watching this thread, this is not a bug, default ES6 import is not supported yet, |
Ok thanks! |
* added initial package.json * installed dependencies, added npm scripts, and added gitignore file. * added ra-data-json-server and react-admin.Admin * added react-admin.Resource and bsconfig.json * fixed typo * trying to get default export to work * used bucklescript workaround to get the default field to work (rescript-lang/rescript#2456) * fixed errors in react-admin.Resource
tl;dr:
import * as Foo from 'foo';
is not equivalent toimport Foo from 'foo';
When compiling to
es6-global
a module external typed as a function, likewill generate the import
which is incorrect since MyFunction imported in this manner is defined as a namespace object. See https://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-objects
It should generate
This causes standards-conforming tools like rollup to throw a fit, which is a pretty serious problem.
My workaround for now is:
The text was updated successfully, but these errors were encountered: