Skip to content
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

Commonjs - preserveModules support #1037

Closed
Kabe0 opened this issue Nov 8, 2021 · 3 comments · Fixed by rollup/rollup#4270
Closed

Commonjs - preserveModules support #1037

Kabe0 opened this issue Nov 8, 2021 · 3 comments · Fixed by rollup/rollup#4270

Comments

@Kabe0
Copy link

Kabe0 commented Nov 8, 2021

  • Rollup Plugin Name: commonjs
  • Rollup Plugin Version: latest

Feature Use Case

When preserveModules on output is set to true, the commonjs plugin currently creates invalid files in the _virtual folder. Example of this is something as simple as a import like

import VueFroala from "vue-froala-wysiwyg/dist/vue-froala.js";

When I attach a debugger to the plugin process, the transform is showing

~/Documents/Experiments/Rollup/node_modules/vue-froala-wysiwyg/dist/vue-froala.js?commonjs-module

Ext: .js?commonjs-module

That makes a file in the _virtual folder called
vue-froala.js_commonjs-module
which is not readable in the browser...

Feature Proposal

Change the way new ID's are generated inside the application. Currently in the helper.js, it has multiple SUFFIX's defined. If they were to have a .js extension added to the end, the files would function as expected. While the hack below works alright, it will create weird files with two .js extensions which is not ideal.

export const PROXY_SUFFIX = '?commonjs-proxy.js';
export const REQUIRE_SUFFIX = '?commonjs-require.js';
export const EXTERNAL_SUFFIX = '?commonjs-external.js';
export const EXPORTS_SUFFIX = '?commonjs-exports.js';
export const MODULE_SUFFIX = '?commonjs-module.js';
@lukastaegert
Copy link
Member

By "invalid" you just mean that there is no extension? Browsers should have no problem reading JavaScript files without extensions as they do not look at extensions at all, they just look at MIME types. It could however be that your server has a problem inferring the correct MIME type if there is no extension.

@Kabe0
Copy link
Author

Kabe0 commented Nov 8, 2021

Yes that's what I meant.

If someone however is using the browser without a server running it won't work. Even with a MIME type specified, having no extension can result in some pretty weird behaviour. I have seen browsers (such as Chrome) cache a home page in place of a vendor resource, and not release it even with a cache reset. In general it's not a great idea to infer the extension of a file.

@BPScott
Copy link

BPScott commented Nov 13, 2021

I think this and #1031 share an underlying issue.

I think the general solution to both these issues is rollup/rollup#4269 - making it so virtual files pick up their filename based upon output.entryFileNames - which by default will give files created from virtual chunks a .js extension on disk, rather than not performing any filename transform at all.

There have been various other bandaid fixes relating to this issue too rollup/rollup-plugin-commonjs#373 / rollup/rollup-plugin-babel#296

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants