为什么npx在父目录中找不到package.json?

问题描述

目标:'npx elm make'在GitLab CD中成功运行

背景:我在GitLab页面上有一个玩具前端项目,并且为此写了一个粗略的CI / CD管道。这包括使用elm文件构建子目录。它工作了一段时间,然后突然坏了,我似乎无法修复。

脚本如下:

cd public/scripts/
npm i
cd elm/
npx elm make src/Main.elm --output=index.js

,然后继续执行脚本的其余部分。

这些说明在我的机器上正常工作。

问题:“ npx elm make”在elm目录中查找 package.json

这是失败的构建的输出

Running with gitlab-runner 13.5.0-rc2 (71c90c86)
  on docker-auto-scale z3WU8uu-
Resolving secrets
00:00
Preparing the "docker+machine" executor
Using Docker executor with image node:latest ...
Pulling docker image node:latest ...
Using docker image sha256:ca36fba5ad66b0f8fce2b97a6f0aa53267395388ada988534d848638312ccb68 for node:latest with digest node@sha256:bf60a164bc588967ce6e3342c9d6508bf9ad2e7e2a1c237315596eab3e13428b ...
Preparing environment
00:03
Running on runner-z3wu8uu--project-21153296-concurrent-0 via runner-z3wu8uu--srm-1603581774-6b7f1e48...
Getting source from Git repository
00:23
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/chicagotestout/chicagotestout.gitlab.io/.git/
Created fresh repository.
Checking out b73b89bb as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:01
$ cd public/scripts/
$ npm i
up to date,audited 49 packages in 644ms
found 0 vulnerabilities
$ cd elm/
$ npx elm make src/Main.elm --output=index.js
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /builds/chicagotestout/chicagotestout.gitlab.io/public/scripts/elm/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory,open '/builds/chicagotestout/chicagotestout.gitlab.io/public/scripts/elm/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-10-24T23_24_44_668Z-debug.log
Cleaning up file based variables
00:01
ERROR: Job Failed: exit code 1

因此,它正在elm子目录中寻找 package.json 文件。好的。但是我那里没有(也不需要,也不想)一个 package.json 文件。相关的 package.json 文件位于安装了elm的父目录(脚本)中。

混杂因素

您可能想知道在退出工作时破坏了构建的提交中有什么内容,但是该提交中没有任何东西应该以这种方式破坏了构建。提交没有涉及任何配置文件,只有一些 .elm 文件

我的直觉说这是npm的事情,但我不能完全排除这是榆木还是gitlab-ci的想法。

我已经搜索了这个问题,但似乎这是一个非常不常见的问题,而且我正在努力过滤掉其他 package.json 搜索字词。

总结

如何让npx在父目录中查找适当的 package.json

帮助表示赞赏。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)