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

exports is not defined #3939

Closed
SunLxy opened this issue Aug 11, 2023 · 8 comments
Closed

exports is not defined #3939

SunLxy opened this issue Aug 11, 2023 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@SunLxy
Copy link

SunLxy commented Aug 11, 2023

System Info

System:
OS: macOS 13.4.1
CPU: (10) arm64 Apple M1 Max
Memory: 7.44 GB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 16.15.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 8.5.5 - /usr/local/bin/npm
pnpm: 7.8.0 - /usr/local/bin/pnpm
Watchman: 2023.04.17.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 115.0.5790.170
Safari: 16.5.2
npmPackages:
@rspack/cli: 0.2.11 => 0.2.11

Details

代码块中不能直接写 Object.defineProperty(exports, "__esModule", { value: true })

image image

Reproduce link

No response

Reproduce Steps

  1. npm install
  2. npm run dev
@SunLxy SunLxy added bug Something isn't working pending triage The issue/PR is currently untouched. labels Aug 11, 2023
@hardfist
Copy link
Contributor

can you help check the behavior of webpack?

@underfin
Copy link
Contributor

The webpack will render to

var __webpack_unused_export__;

__webpack_unused_export__ = ({ value: true })

@underfin underfin self-assigned this Aug 11, 2023
@underfin underfin removed the pending triage The issue/PR is currently untouched. label Aug 11, 2023
@hyf0 hyf0 self-assigned this Aug 11, 2023
@SunLxy
Copy link
Author

SunLxy commented Aug 12, 2023

看了一下编译后的代码没有转换

image

@ScriptedAlchemy
Copy link
Contributor

This is with an ESM output, correct?

@SunLxy
Copy link
Author

SunLxy commented Aug 17, 2023

这个就是初始化的项目,没加其他的配置 @ScriptedAlchemy
image

@daydayhappychao
Copy link
Contributor

如果你的文件最终没有导出内容的话,构建工具会按 esm 处理,模块参数的第二项会是 webpack_exports 而不是 exports, webpack 也是这个逻辑,改一下你的 loader 中的模块化方案为 esm 就可以解决这个问题(当然为你的文件随便导出个啥让构建工具能知道你的文件类型是 commonjs 也可以

Copy link

stale bot commented Dec 19, 2023

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@ahabhgk
Copy link
Contributor

ahabhgk commented Jul 4, 2024

This should already been fixed by #6883

@ahabhgk ahabhgk closed this as completed Jul 4, 2024
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

7 participants