gpt4 book ai didi

npm-install - netlify 部署中没有 node_modules

转载 作者:行者123 更新时间:2023-12-03 23:13:39 29 4
gpt4 key购买 nike

我已经使用 Netlify 和 git repo 进行了持续部署设置,但到目前为止,无论我做什么,Netlify 都不是 npm-install什么。当我下载部署的 zip 文件时,没有 node_modules 文件夹,我的站点无法访问 node_modules,它只是不存在。我已经开始使用一个随机的 npm 包 (lodash) 来尝试安装它,但到目前为止我什么都没有。

Netlify 说它会自动运行 npm install .我试过没有构建命令,我试过添加 npm install作为构建命令,两者都没有结果。

包.json:

{
"name": "netlify-test",
"version": "1.0.0",
"description": "stuff",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/electrovir/netlify-test.git"
},
"author": "electrovir",
"license": "MIT",
"bugs": {
"url": "https://github.com/electrovir/netlify-test/issues"
},
"homepage": "https://github.com/electrovir/netlify-test#readme",
"dependencies": {
"lodash": "^4.17.11"
}
}

HTML:

<!doctype html>
<html>

<head>
<title>
hi
</title>
<script src="node_modules/lodash/_apply.js"></script>
</head>

<body>
Why can't this find node_modules??
</body>

</html>

最佳答案

花了一段时间才弄清楚这一点,但我发现 Netlify 确实 npm install进入你的仓库根目录或 基本目录 当您有 package.json .这可以通过更改 来看到。构建命令 类似于 ls并阅读部署控制台输出(将列出 node_modules 文件夹)。

但是,在运行 后的某个时刻构建命令 在部署之前,这个 node_modules被删除。因此,如果您使用类似于以下内容的 构建命令 , node_modules可以复制到您的发布目录 :

rm -rf dist && mkdir dist && rsync -rv * dist --exclude ./dist

这复制了 基本目录 内容进入 dist ,我已将其设置为我的 发布目录 ,忽略 ./dist自身(不能复制到自身中)。如果将此作为 npm 脚本添加到 package.json 中会更好与 npm run <script name>为您 构建命令 .

请注意 基本目录 , 构建命令 , 和 发布目录都在 Deploys > Deploy settings 或 Settings > Build & deploy in Netlify 下。

感谢 lastmjs帮助解决这个问题。

关于npm-install - netlify 部署中没有 node_modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54527465/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com