我在 Windows 上使用 Docker。
错误:
Step 4/5 : RUN npm install -g
---> Running in ec6582e10f69
+ lfg-auth@1.0.0
added 1 package in 0.437s
Removing intermediate container ec6582e10f69
---> f2b9a25a51a3
Step 5/5 : RUN npm run build-tsc
---> Running in 6321ac31e370
> lfg-auth@1.0.0 build-tsc /app
> tsc
/app/node_modules/.bin/tsc: line 1: XSym: not found
/app/node_modules/.bin/tsc: line 2: 0021: not found
/app/node_modules/.bin/tsc: line 3: 8cbd85238d8fbeb66a0afc1d79bcd880: not found
/app/node_modules/.bin/tsc: line 4: ../typescript/bin/tsc: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! lfg-auth@1.0.0 build-tsc: `tsc`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the lfg-auth@1.0.0 build-tsc script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-02-17T09_27_42_522Z-debug.log
ERROR: Service 'auth' failed to build: The command '/bin/sh -c npm run build-tsc' returned a non-zero code: 1
Run Code Online (Sandbox Code Playgroud)
Dockerfile:
FROM node:8.15.0-alpine
ADD . /app/
WORKDIR /app
RUN npm install -g
RUN npm run build-tsc
Run Code Online (Sandbox Code Playgroud)
包.json:
"scripts": {
...
"build-tsc": "tsc",
...
},
"dependencies": {
...
"typescript": "^3.3.3"
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试在 docker 容器中的终端内运行相同的命令,它可以完美运行。使用 docker-compose 如果我把它放在命令字段中它也可以正常工作。
react-scripts build当我将 Windowsnode_modules/文件夹安装在 Linux 容器内时,我看到了这个问题。最有可能的是,您npm install在 Windows 中运行,然后node_modules/在构建时复制到映像中,或者将本地项目文件夹安装为 Docker 卷。无论哪种方式,当您尝试在 Linux 上运行 Windows 可执行文件时,它都会崩溃。
从技术上讲,这是因为二进制文件的内容/app/node_modules/.bin/tsc看起来像
XSym
0021
8cbd85238d8fbeb66a0afc1d79bcd880
../typescript/bin/tsc
Run Code Online (Sandbox Code Playgroud)
您应该能够通过添加node_modules/到.dockerignore文件来解决构建时问题。
如果像我一样,您稍后将本地项目目录挂载在容器内用于开发目的,您仍然需要手动丢弃该node_modules/文件夹并npm install从容器内再次运行。
| 归档时间: |
|
| 查看次数: |
2047 次 |
| 最近记录: |