在我完全发疯之前,也许有人遇到过类似的问题(否则,我想我必须深入研究源头......)。
我在 NPM 上有几个包。通常我会在 package.json 中指定“files”数组,以便能够排除某些内容(例如,我在源代码中写入 ES6)。所以,这有效 - 没问题。
现在,一个包的 /dist/ 文件夹中包含其他文件(即一些 PNG)。/dist/ 文件夹中的内容已更新,但 PNG 丢失。我执行了 rm -rf node_modules 并使用 yarn 重新安装,但无济于事。包的 node_modules 文件夹中的 package.json 显示正确的版本和内容。它绝对是最新版本。
(还有一个包含源 PNG 的资产文件夹 - 在 dist 中有一个精灵图 - 但它也丢失了。)
我以为我疯了,于是我创建了一个空项目并运行
yarn init && yarn add $my-module.
你知道吗?
monomelodies@marijn:~/blabla$ ls node_modules/monad-theme-default/
assets dist LICENSE package.json README.md sass
monomelodies@marijn:~/blabla$ ls node_modules/monad-theme-default/dist/assets/
i18n.png logo.png
monomelodies@marijn:~/blabla$
所以,这似乎工作得很好。正如我所料,我检查了 npm pack 的内容,发现它们是完整的。
查看使用该包的另一个项目,它也完全没问题:
monomelodies@marijn:~/sites/projects/sensi/flirttracker$ ls node_modules/monad-theme-default/
assets dist LICENSE package.json README.md sass
monomelodies@marijn:~/sites/projects/sensi/flirttracker$
我的其他项目仍然无法获得正确的文件:
monomelodies@marijn:~/sites/projects/sensi/sensi$ rm -rf node_modules/
monomelodies@marijn:~/sites/projects/sensi/sensi$ yarn
yarn install v1.12.3
warning package.json: License should be a valid SPDX license expression
warning [email protected]: License should be a valid SPDX license expression
[1/6] Validating package.json...
warning [email protected]: License should be a valid SPDX license expression
[2/6] Resolving packages...
[3/6] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[4/6] Linking dependencies...
warning " > [email protected]" has unmet peer dependency "[email protected] - 3".
warning " > [email protected]" has unmet peer dependency "popper.js@^1.14.7".
warning " > [email protected]" has unmet peer dependency "@angular/core@>=4.0.0 <5.0.0".
warning " > [email protected]" has unmet peer dependency "highlight.js@^9.9.0".
warning " > [email protected]" has unmet peer dependency "browserify@>=10 <17".
warning " > [email protected]" has unmet peer dependency "watchify@>=3 <4".
[5/6] Building fresh packages...
[6/6] Cleaning modules...
Done in 13.89s.
monomelodies@marijn:~/sites/projects/sensi/sensi$ ls node_modules/monad-theme-default/
dist LICENSE package.json sass
monomelodies@marijn:~/sites/projects/sensi/sensi$ cat package.json | grep monad-theme
"monad-theme-default": "^1.3.7",
monomelodies@marijn:~/sites/projects/sensi/sensi$ cat node_modules/monad-theme-default/package.json | grep version
"version": "1.3.7",
另外,我在 .gitignore 中没有看到任何奇怪的东西(但我认为这并不重要);
monomelodies@marijn:~/sites/projects/sensi/sensi$ cat .gitignore
# oh for fuck's sake... :)
httpdocs/how_long.php
httpdocs/agy
.sass-cache
node_modules
src/Smile/tmp/smile*
bower_components
vendor
.twig-cache/*
.smile-cache/*
cache/*.png
cache/*.jpg
cache/*.jpeg
assets
httpdocs/css/*.css
httpdocs/js
httpdocs/admin
!httpdocs/admin/fonts
/tmp/
/uploads/
Versions.json
有谁有任何主意?
目前我唯一能想到的就是本地的 .gitignore还列出了一个名为 /assets/ 的文件夹,但真的吗?它也没有解释包的 /dist/ 文件夹中丢失的文件……
答案1
.yarnclean
检查有问题的项目中是否有文件。它可以自动删除包中的某些元素,例如资产。