-
-
Notifications
You must be signed in to change notification settings - Fork 599
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
Isomorphic code is no longer isomorphic #348
Comments
|
If this file wasn't getting transpiled, it would work; i'm pretty sure the source code is a valid es module even though it "uses" require. Could there be a bug in the logic to skip es modules? |
It is a valid ES module, but in a valid ES module Also, how is this isomorphic if you expect export statements to work in your target environment? In browsers, you can only place this in a script tag if the type is |
Ah sorry, reading your issue again, maybe I slightly misunderstood the problem. The thing is, |
@lukastaegert Looks like the behaviour of detection was changed. Now this issue appears here and there because of it. |
I can confirm we can't longer compile stencil with rollup because the commonjs plugin is trying to wrap ESmodule code around the commonjs wrapper, leading to |
@lukastaegert I think this is achievable; I can see that the plugin is already replacing references to |
A PR would surely be welcome but the question is what it should actually do. So if by default, |
Same for me when using 'symbol-observable'
|
Hmm, looking at the problem again I see your point, turning The file that's causing me trouble is a valid ES module, which works (without transpilation) in both the browser and Node 8+. It's trying to use a My problem is that the commonjs plugin is transpiling that conditional Tricking the commonjs transform tool into thinking that |
The thing I overlooked is that my comment #348 (comment) is actually no longer valid because #206 changed semantics to always process modules if they contain global So what we would need here would be a toggle to switch back to the old behaviour which was to not process any file that contains mixed ESM and CJS syntax. Would this work for you?@danielgindi as you are more intimate with that code, what do you think? Or maybe you have another idea? |
As such, it would actually be a duplicate of #342 |
I think that the latest PR should have fixed it. Should try and see. If all hell breaks loose sure we can revert to the old behavior where we don’t even look in ES module files- but that will break behavior where an ES module actually uses We could also easily add a check for “typeof require”- which will make it much smarter, and will be very easy to implement. |
My understanding is that the latest PR just avoided adding a wrapper but would still bundle the file in question. If |
@lukastaegert Yes you raise a good point. We probably have no good way of knowing whether the user intend for the module to be transpiled for the browser (hence |
Well for this specific case the right path would be to use include/exclude to mark code that should not be transformed and code that should. We will have a kill switch for this soon anyway, so any breakage will be fixed. But people should really start sorting out their mess. |
…llup#348, rollup#342) `transformMixedEsModules = false`
If this code is inside of a dependency which is explicitly an ES module (i.e. package.json has a "module" field), does it make sense to automatically exclude it? Or would that mess with its (potentially non-ES-module) dependencies? |
BREAKING CHANGE: Reverts default behavior of mixed es and cjs modules. Marked as a "breaking change", but the PR that raised this need was actually a breaking change for people who did not utilize include/exclude correctly and have variety of dependencies with mixed UMD mechanisms. * Implemented kill-switch for mixed commonjs in mixed es-cjs (Closes rollup#348, rollup#342) `transformMixedEsModules = false` * Update packages/commonjs/README.md Co-authored-by: Andrew Powell <shellscape@users.noreply.github.com> * Update index.d.ts Co-authored-by: Andrew Powell <shellscape@users.noreply.github.com>
How Do We Reproduce?
Repro repo at https://github.com/SupernaviX/rollup-plugin-commonjs-broken-isomorphic-require
Bundle a module which checks if
require
is defined, and requires a module if it is.Expected Behavior
Since the require statement will never be called in the browser, it should ideally be transpiled out. Since the original code worked in the browser, the new code should work too.
Actual Behavior
The require statement is converted into a static import. Even though the module is never actually used, it becomes a hard dependency and the file no longer works in the browser.
Relevant snippet of code:
This might be a duplicate of #342, I'm not sure.
The text was updated successfully, but these errors were encountered: