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] docker 中运行 npm run dev 出现Segmentation fault #12013

Open
hanxiaolong-github opened this issue Dec 28, 2023 · 14 comments
Open

[Bug] docker 中运行 npm run dev 出现Segmentation fault #12013

hanxiaolong-github opened this issue Dec 28, 2023 · 14 comments

Comments

@hanxiaolong-github
Copy link

What happens?

我在 mac M1 上使用docker 开发 umi max 项目根据 文档https://v3.umijs.org/docs/getting-started 创建新的项目后,当执行npm run dev 启动项目的时候出现 Segmentation fault Command failed with exit code 139.

Mini Showcase Repository(REQUIRED)

Please provide a minimal reproduction then upload to your GitHub. 请提供 最小重现,并上传到你的 GitHub 仓库

How To Reproduce

Steps to reproduce the behavior: 1. 2.

Expected behavior 1. 2.

build:run:postinstall:node_modules/tsx/node_modules/esbuild Completed in 200ms
9521 timing build:run:postinstall Completed in 541ms
9522 timing build:deps Completed in 740ms
9523 timing build Completed in 742ms
9524 timing reify:build Completed in 760ms
9525 timing reify:trash Completed in 63ms
9526 timing reify:save Completed in 585ms
9527 timing reify Completed in 247377ms
9528 timing command:install Completed in 251168ms
9529 verbose stack Error: command failed
9529 verbose stack at ChildProcess. (/root/.nvm/versions/node/v16.20.2/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:63:27)
9529 verbose stack at ChildProcess.emit (node:events:513:28)
9529 verbose stack at maybeClose (node:internal/child_process:1100:16)
9529 verbose stack at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)
9530 verbose cwd /SSO/test3
9531 verbose Linux 5.10.104-linuxkit
9532 verbose node v16.20.2
9533 verbose npm v8.19.4
9534 error code 139
9535 error path /SSO/test3
9536 error command failed
9537 error command sh -c -- max setup
9538 verbose exit 139
9539 timing npm Completed in 251397ms
9540 verbose code 139
9541 error A complete log of this run can be found in:
9541 error /root/.npm/_logs/2023-12-28T11_03_05_481Z-debug-0.log

  • Umi Version: latest
  • Node Version: 16
  • Platform: docker ubuntu 18 .
Copy link

由于缺乏足够的信息,我们暂时关闭了该 Issue。请修改(不要回复) Issue 提供最小重现以重新开启。谢谢。

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 28, 2023
@hanxiaolong-github
Copy link
Author

hanxiaolong-github commented Dec 29, 2023

@fz6m 能帮忙看看这个问题吗?我在windows 和ubuntu 上安装docker 运行时没问题的,就是M1 MAC 不行。没有code 没法提供最小重现, 补充一下:react 项目有这个错误,vue的没问题。

@fz6m
Copy link
Member

fz6m commented Dec 31, 2023

创建一个新项目使用如下命令:

  pnpm create umi my-app

参考 https://umijs.org/docs/guides/getting-started

@hanxiaolong-github
Copy link
Author

hanxiaolong-github commented Jan 2, 2024

这个试过的。pnpm dlx create-umi@latest; npx create-umi@latest; yarn create umi 我都尝试过一样的错误,执行到 info - Preparing... 程序就不执行了。我也尝试过更换 docker 镜像例如:FROM ubuntu:20.04; FROM ubuntu:18.04; FROM centos:7; FROM debian,都是一样的错误。我把版本切换到umi3 是没问题的[yarn create @umijs/umi-app]。我在 ubuntu 上安装docker 并且在docker 中执行pnpm dlx create-umi@latest 也没问题。应该确定就是mac M1 中安装docker 开发 umi4 有问题。
执行:cnpm i 能看到错误。

image

@fz6m 希望帮忙看看这个问题。

@fz6m
Copy link
Member

fz6m commented Jan 3, 2024

umi 4 使用了很多包含编译后二进制分发的包(esbuild / swc 解析器等),这些包会在安装时安装对应平台的二进制文件,如果你的虚拟环境没法正确识别平台安装了错误的平台二进制包,或者虚拟环境并不是完全被实现的,都有可能导致无法使用这些第三方库启动不了。

所以推荐在本地真实环境而非虚拟环境中进行开发,如果要在虚拟环境中开发,需要自行排查虚拟环境问题。

@yeling
Copy link

yeling commented Jan 16, 2024

建议打开这个issue,也碰到了同样的问题,demo跑不通

Mac M2芯片,
macOS 13.6.3

docker镜像采用ubuntu:24.04

运行自己的项目和按照文档创建项目是同样的结果 https://umijs.org/docs/guides/getting-started

image

@fz6m
Copy link
Member

fz6m commented Jan 17, 2024

可以辛苦协助帮看下这两个代码片段是否可以正常运行吗?(在发生问题的同环境下),这有助于帮助我们定位是这个工具运行时的问题,感谢。

检验 @umijs/es-module-parser 是否可以正常运行

  pnpm add -D @umijs/es-module-parser tsx
// index.ts

import a from 'b'
// script.ts

import { parseFiles } from '@umijs/es-module-parser'
import path from 'path'

const run = async () => {
  const res = await parseFiles([path.join(__dirname, './index.ts')])
  console.log(res)
}

run()
  pnpm tsx ./script.ts

检验 rs-module-lexer 是否正常运行

  pnpm add -D rs-module-lexer tsx
import { parse } from 'rs-module-lexer'
import assert from 'assert'

const run = async () => {
  const res = await parse({
    input: [
      {
        filename: 'index.ts',
        code: `import a from 'b'`,
      },
    ],
  })
  assert(res.output[0].imports.length, 1)
}

run()
  pnpm tsx ./index.ts

@yeling
Copy link

yeling commented Jan 17, 2024

es-module-parser 这个模块问题,
vim ./node_modules/.pnpm/@umijs+preset-umi@4.1.0_@types+react@18.2.48_typescript@5.3.3_webpack@5.89.0/node_modules/@umijs/preset-umi/dist/features/prepare/prepare.js

      console.log("Phoebe 1")
      const fileImports = await parser.parseFiles(
        files.map((f) => import_path.default.join(api.paths.cwd, f))
      );
      console.log("Phoebe 2")

parser定义如下

var parser = (0, import_utils.importLazy)(
  require.resolve("@umijs/es-module-parser")
);

执行命令 npx umi setup
输出如下日志

info  - [你知道吗?] 全局布局用 layout ,多层布局用 wrappers ,从文档了解更多路由的控制方法,详见 https://umijs.org/docs/guides/routes
info  - generate files
info  - Preparing...
Phoebe 1
Segmentation fault

Phoebe 2 没有打印出来

我给 es-module-parser 也提了个issue umijs/es-module-parser#2

@fz6m
Copy link
Member

fz6m commented Jan 18, 2024

@yeling 感谢帮助排查问题 🌹 ,可以再帮试一下相同环境中 rs-module-lexer 的代码片段可以手动运行吗,想对比一下这两个工具的可运行性来确定下是不是构建参数的问题

@yeling

This comment was marked as resolved.

@stormslowly
Copy link
Member

@yeling
Copy link

yeling commented Jan 30, 2024

更新一下,在 @stormslowly 提示下,node版本升级到18之后,就没有这个问题了。

@fz6m
Copy link
Member

fz6m commented Jan 30, 2024

这个问题的根源不是 node 版本升级了就解决这么简单吧,我初步目测和构建配置有关。

@yeling
Copy link

yeling commented Jan 30, 2024

root cause没有找到,升级之后确实没有这个问题了。构建步骤都是按照官方流程来的,大概怀疑跟那几个 .node文件有关系。

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

No branches or pull requests

4 participants