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

[Bug Report]: output.library.type = 'module' not outputting ESM correctly #2293

Closed
thebreiflabb opened this issue Mar 16, 2023 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@thebreiflabb
Copy link

System Info

System:
OS: Linux 5.10 Ubuntu 20.04 LTS (Focal Fossa)
CPU: (12) x64 Intel(R) Core(TM) i7-10810U CPU @ 1.10GHz
Memory: 1.63 GB / 15.51 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
Yarn: 1.22.15 - ~/.nvm/versions/node/v16.13.0/bin/yarn
npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
npmPackages:
@rspack/cli: 0.1.1 => 0.1.1

Details

The output.library.target = 'module' does not output ESM modules, support for this is mentioned in the documentation: https://www.rspack.dev/config/output.html#outputlibrarytype
In Webpack this worked when an experiment was enabled: https://webpack.js.org/configuration/output/#module-definition-systems

# ./rspack.config.js
const path = require('path');

module.exports = {
  entry: {
    add: './src/add.js',
  },
  target: 'es2020',
  output: {
    filename: '[name].bundle.mjs',
    path: path.resolve(__dirname, 'dist'),
    library: {
      type: 'module',
    },
  },
};
# ./src/add.js
export const add = (a, b) => a + b

This gives output of

# ./dist/add.bundle.mjs
!function(){var e={380:function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),Object.defineProperty(r,"add",{enumerable:!0,get:function(){return n}});let n=(e,r)=>e+r}},r={};!function t(n){var o=r[n];if(void 0!==o)return o.exports;var u=r[n]={exports:{}};return e[n](u,u.exports,t),u.exports}("380")}();
//# sourceMappingURL=add.bundle.mjs.map

I would expect it to output something along the lines of the original source using export

# expected
const add = (a, b) => a + b

export { add }

Reproduce link

https://github.com/thebreiflabb/rspack-es-module-error-repro

Reproduce Steps

pnpm install
pnpm build
pnpm test

The test fails because the outputted dist/add.bundle.mjs does not export { add }

@thebreiflabb thebreiflabb added the bug Something isn't working label Mar 16, 2023
@hardfist
Copy link
Contributor

sorry we are not supportting esm output yet

@FlorianRappl
Copy link

When is esm output supported? We need esm and system. What can be done to support this?

@zackarychapple
Copy link
Collaborator

This will be easier to land after webpack/webpack#17121 and by extension webpack/webpack#2933 lands in webpack.

@hardfist
Copy link
Contributor

hardfist commented May 6, 2023

esm output is supported, please check it in @0.1.19 version

@thebreiflabb
Copy link
Author

Awesome, it works with the new version when enabling experiments.outputModule = true, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants