web-infra-dev / modern.js

Modern.js is a web engineering system, including a web framework and a npm package solution.
https://modernjs.dev/en/
MIT License
4.38k stars 366 forks source link

[Bug]: github工作流中yarnbuild 会完成打包但是无法自动退出命令行 #6162

Open katocrane opened 1 week ago

katocrane commented 1 week ago

Version

System:
    OS: macOS 13.6.4
    CPU: (8) arm64 Apple M2
    Memory: 118.34 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 128.0.6613.114
    Safari: 16.6
  npmPackages:
    @modern-js/app-tools: 2.58.2 => 2.58.2 
    @modern-js/eslint-config: 2.58.2 => 2.58.2 
    @modern-js/runtime: 2.58.2 => 2.58.2 
    @modern-js/tsconfig: 2.58.2 => 2.58.2

Details

本地打包似乎是每次modern.config.ts更改过后进行yarnbuild,就会出现日志已经说明打包完成但是不退出命令行的情况;生产环境的workflow会永远无法退出命令行导致工作流卡住 ![Uploading screenshot-20240903-161933.png…]() image

Reproduce link

https://gist.github.com/katocrane/059c64273aa175407b9d99bc01a144ee

Reproduce Steps

执行yarn build

botagar commented 1 week ago

I had the same issue with with pnpm build. I switched to to using rspack as the bundler and it fixed this hanging problem. Seems like it's an issue with the Webpack integration?

In modern.config.js

appTools({
  bundler: 'rspack',
}),
chenjiahan commented 1 week ago

Try this package to find the root cause: https://www.npmjs.com/package/why-is-node-running

katocrane commented 1 week ago

why-is-node-runningI tried to use this library but it didn't compile into modern.js successfully. Do you have any good code snippets for reference?

chenjiahan commented 1 week ago

You can use it in the edenx.config.ts file

katocrane commented 1 week ago

` tools: { styledComponents: false,

webpack: config => {
  // 确保 config.plugins 已被定义
  config.plugins = config.plugins || [];

  // 添加自定义 DonePlugin 插件 在生产环境下保证打包后退出终端命令
  if (process.env.NODE_ENV === 'production') {
    config.plugins.push({
      apply: compiler => {
        compiler.hooks.done.tap('DonePlugin', () => {
          setTimeout(() => {
            console.log('✨ Build completed. Exiting process.');
            whyIsNodeRunning();
            // process.exit(0); // 构建完成后强制退出
          });
        });
      },
    });
  }
},

},`

`> yarn build yarn run v1.22.22 warning package.json: No license field $ modern build Modern.js Framework v2.58.2

info Starting production build... info Type checker is enabled. It may take some time. ready Compiled in 18.7 s (web) ✨ Build completed. Exiting process. There are 62 handle(s) keeping the process running.

FILEHANDLE

(unknown stack trace)

FILEHANDLE

(unknown stack trace)

FILEHANDLE

(unknown stack trace)

FILEHANDLE

(unknown stack trace) error TypeError: Cannot read properties of null (reading 'startsWith') at /Users/mac/Documents/youjiaassessmanage/node_modules/.cache/bundle-require/modern.config.PENeOo51.cjs:66:77 at Array.filter () at printStacks (/Users/mac/Documents/youjiaassessmanage/node_modules/.cache/bundle-require/modern.config.PENeOo51.cjs:66:39) at whyIsNodeRunning (/Users/mac/Documents/youjiaassessmanage/node_modules/.cache/bundle-require/modern.config.PENeOo51.cjs:62:5) at Timeout._onTimeout (/Users/mac/Documents/youjiaassessmanage/node_modules/.cache/bundle-require/modern.config.PENeOo51.cjs:153:17) at listOnTimeout (node:internal/timers:573:17) at processTimers (node:internal/timers:514:7) ◯ web ━━━━━━━━━━━━━━━━━━━━━━━━━ 99% done error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.`

As you can see, I have already integrated it, but it seems to have a problem. I have done a series of troubleshooting but it has not been solved.