我正在尝试编译 Nativescript 应用程序作为我们 Teamcity 部署策略的一部分。
当我运行 NPM install 时,尝试查找文件时出现 ENOENT 错误,如下所示:
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-7722a2ea/fp/assignAll.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-8fa77886/fp/create.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-7722a2ea/fp/assignAllWith.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-b2787570/fp/assign.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-8fa77886/fp/curry.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-b2787570/fp/assignAll.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-7722a2ea/fp/assignIn.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-8fa77886/fp/curryN.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-b2787570/fp/assignAllWith.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-7722a2ea/fp/assignInAll.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-7722a2ea/fp/assignInAllWith.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-8fa77886/fp/curryRight.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-b2787570/fp/assignIn.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-8fa77886/fp/curryRightN.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-b2787570/fp/assignInAll.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-7722a2ea/fp/assignInWith.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-b2787570/fp/assignInAllWith.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-8fa77886/fp/date.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-7722a2ea/fp/assignWith.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-7722a2ea/fp/assoc.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-8fa77886/fp/debounce.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-7722a2ea/fp/assocPath.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-b2787570/fp/assignInWith.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-8fa77886/fp/deburr.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-7722a2ea/fp/at.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-b2787570/fp/assignWith.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-8fa77886/fp/defaults.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-b2787570/fp/assoc.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-7722a2ea/fp/attempt.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-8fa77886/fp/defaultsAll.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-b2787570/fp/assocPath.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/browserify-117e4a8d/test/shared_symlink/shared/index.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-7722a2ea/fp/before.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-8fa77886/fp/defaultsDeep.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-b2787570/fp/at.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-8fa77886/fp/defaultsDeepAll.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-7722a2ea/fp/bind.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-b2787570/fp/attempt.js'
npm WARN tar ENOENT: no such file or directory, open '/home/my_user/BuildAgent/work/my_application/node_modules/.staging/lodash-8fa77886/fp/defaultTo.js'
我尝试在发出
node_modules
之前清理 ~/.npm
文件夹、package-lock.json
和 npm install
,在不同的容器中运行相同的内容,在运行 npm install
之前清理 teamcity 中的 checkout 文件夹,更改 checkout 文件夹并我能想到的一切。我也跑过npm cache clear --force
。
我还尝试在本地计算机上使用相同的容器运行相同的步骤,并且编译正常。
似乎有一些与 npm 相关的脏数据或类似的东西导致了这种情况,但我无法找出是什么。
这是正在使用的dockerfile:
FROM ubuntu:18.04
USER root
ENV ANDROID_HOME=/android-sdk PATH=$PATH:/android-sdk/tools:/android-sdk/tools/bin:/android-sdk:/platform-tools
RUN apt-get update && apt-get install -y sudo lib32z1 lib32ncurses5 g++ unzip openjdk-8-jdk zsh-common curl gnupg2 git
RUN curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - && \
apt-get install -y nodejs && \
curl "https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip" -o /tmp/sdk.zip && \
mkdir -p /android-sdk && \
unzip -q /tmp/sdk.zip -d /android-sdk && \
mkdir -p /root/.android/ && touch /root/.android/repositories.cfg && \
rm -rf /tmp/* && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/lib/apt/*
RUN echo "export JAVA_OPTS=\"$JAVA_OPTS\"" >> /root/.bashrc && \
echo "export ANDROID_HOME=$ANDROID_HOME" >> /root/.bashrc && \
echo "export PATH=$PATH" >> /root/.bashrc
RUN yes | /android-sdk/tools/bin/sdkmanager --licenses && \
/android-sdk/tools/bin/sdkmanager "tools" "platform-tools" "platforms;android-28" "build-tools;28.0.3" "extras;google;m2repository" "extras;android;m2repository"
RUN yes | npm install [email protected] -g --unsafe-perm && \
tns extension install [email protected] && \
tns usage-reporting disable && \
tns error-reporting enable
RUN nativescript doctor
我该如何清理它?
更新
我还注意到
npm uninstall loadash
会触发相同的行为和多个明显的消息。
不太清楚为什么...
确保日志输出已结束。
就我而言,是:
npm ERR! code ENOENT
npm ERR! syscall spawn git
npm ERR! path git
npm ERR! errno -2
npm ERR! enoent Error while executing:
npm ERR! enoent undefined ls-remote -h -t ssh://[email protected]/bodymovin/lottie-api.git
npm ERR! enoent
npm ERR! enoent
npm ERR! enoent spawn git ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
如果没有,请检查日志末尾是否存在实际问题。 我在运行 docker 容器时遇到了这种情况,结果发现其中一个包是使用 git 拉取的,正如您在日志中看到的那样,因此 git 命令需要位于运行 npm 命令的用户的 PATH 中。
如果不是这样,日志末尾可能会告诉您实际的错误是什么。 如果不清楚,可能是 package-lock.json 文件包含运行 npm install 时 package.json 生成的旧引用。 尝试删除/重命名它并运行 npm install,然后比较差异。
如果仍然无法解决问题,可能 package.json 的引用太旧而无法由 npm 解析。
您可能在 Linux 系统上寻找的 npm 缓存通常位于 ~/.npm 或 ~/.npm-global 下,具体取决于您配置 npm/node 的方式。
如果这些都不能解决问题,请使用完整的日志以及运行该程序的确切环境和条件来更新您的答案。 如果这只发生在 lodash 上,请尝试看看将其作为依赖项删除后会发生什么。 祝你好运
我遇到这个问题是因为设备上没有剩余空间,不知何故这个错误表现出来了
当使用私有存储库作为依赖项时,如果您的 SSH 密钥未加载到 SSH 代理中(可能未永久存储并且您已重新启动系统),
npm i
可能会导致这些警告。
例如。这个在 package.json 中
"dependencies": {
"dependency-name": "git+ssh://[email protected]:projectname/somerepo.git"
然后,在安装依赖项时,我收到了针对
ALL我的 deps 的
npm WARN tar ENOENT: no such file or directory
警告,直到我将 SSH 密钥重新添加到操作系统的 SSH 代理中。
以下是我对 SSH 密钥的简要说明:
ssh-add -K ~/.ssh/bb_rsa # add an SSH key to your OS' SSH agent
ssh-add ~/.ssh/bb_rsa # add an SSH key to your OS' SSH agent
ssh-add -l bb_rsa # list the keys within your SSH agent
# .ssh/config file
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/bb_rsa
我遇到了同样的问题,我解决这个问题的方法是检查我的工作目录 在我的 dockerfile 中。
FROM node:12
#Create app directory
WORKDIR /user/projects/backend/E-commerce/node-ecommerce
#Install app dependencies
#A wildcard is used to ensure both packages.json AND package-lock.json are copied
#where available (npm@5+)
COPY package*.json ./
RUN npm install
#if you are building your code for production
#RUN npm ci --only=production
#Bundle app source
COPY . .
EXPOSE 4040
CMD [ "node", "server.js" ]
我认为 dockerfile 是您遇到问题的地方,并检查您的依赖项
对我有帮助的是增加 Docker Desktop 中的虚拟磁盘限制(设置 -> 资源)。
docker system prune
也可能有帮助(不要运行它,而不先检查它的作用!)