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
Exported "namespaced imports" are lost when treeshake
is false
#4174
Labels
Comments
milesj
changed the title
Exported "namespaced imports" are lost
Exported "namespaced imports" are lost when Jul 9, 2021
preserveModules
is true?
I created a test repo and this seems to happen regardless of |
milesj
changed the title
Exported "namespaced imports" are lost when
Exported "namespaced imports" are lost
Jul 9, 2021
preserveModules
is true?
I can confirm there is a bug and it is triggered by |
9 tasks
Fix at #4175 |
milesj
changed the title
Exported "namespaced imports" are lost
Exported "namespaced imports" are lost when Jul 11, 2021
treeshake
is false
@lukastaegert Awesome, thanks for the quick fix! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rollup Version
2.53.0
Operating System (or Browser)
Linux, macOS
Node Version (if applicable)
10+
Link To Reproduction
https://github.com/milesj/rollup-preserve-namespaces
PR I encountered it: milesj/boost#151
Expected Behaviour
It looks like namespace imports that are not used but are exported are dropped, for example this fails:
However, namespace imports that are used within the same file that are exported persist, for example this passes:
Discovery
I started updating a project of mine to the latest Rollup version, and immediately noticed that a ton of unit tests are failing with the following errors (as seen in the REPL/PR link):
This is very weird, as this code hasn't changed in a long time and is pretty straight forward. After digging into it further, it looks like namespaced imports that are exported are completely dropped and are no longer exported in the transpiled output. For example, this code:
Is transpiled to the following. Notice that
json
andyaml
exports do not exist! The files arerequire
d, but they do nothing.As for the other error above, it is also a namespaced import being exported (https://github.com/milesj/boost/blob/master/packages/log/src/index.ts#L7)
Attempts
I've tried different combinations of
interop
,exports
,treeshake
,sourceMaps
, and any option I could think of. None of them seemed to resolve this issue.HOWEVER, when I set
preserveModules
to false and use a single entry point, the export DOES correctly exist.Instead of
export * as X
, I also tried the following. It has the same problem (https://github.com/milesj/boost/blob/master/packages/common/src/index.ts#L15).Config
The configuration is generated by Packemon, which can be found here: https://github.com/milesj/packemon/blob/master/src/rollup/config.ts
Since it's kind of abstracted away, here's a console log of the config while running the build.
Actual Behaviour
Namespaced imports are exported correctly.
It seems to work in the REPL (but cant control preserve modules), so not sure what's happening here: https://rollupjs.org/repl/?version=2.53.0&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmV4cG9ydCUyMColMjBhcyUyMG90aGVyJTIwZnJvbSUyMCcuJTJGb3RoZXIuanMnJTNCJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlN0QlMkMlN0IlMjJuYW1lJTIyJTNBJTIyb3RoZXIuanMlMjIlMkMlMjJjb2RlJTIyJTNBJTIyZXhwb3J0JTIwZnVuY3Rpb24lMjBmb28oKSUyMCU3QiU3RCU1Q25leHBvcnQlMjBmdW5jdGlvbiUyMGJhcigpJTIwJTdCJTdEJTIyJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmNqcyUyMiUyQyUyMm5hbWUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmFtZCUyMiUzQSU3QiUyMmlkJTIyJTNBJTIyJTIyJTdEJTJDJTIyZ2xvYmFscyUyMiUzQSU3QiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE
The text was updated successfully, but these errors were encountered: