部署到Heroku期间的vite错误

发布于 2025-01-30 12:05:19 字数 1016 浏览 0 评论 0 原文

我的文件夹结构:

“文件夹结构”

我的脚本:

"scripts": {
    "start": "node main.mjs",
    "dev": "NODE_ENV='development' npx nodemon main.mjs",
    "build": "cd client && yarn build",
    "install-client": "cd client && yarn",
    "heroku-postbuild": "yarn install-client && yarn build"
  }

client/package.json

"dependencies": {
    ...
},
"devDependencies": {
    ...
    "@vitejs/plugin-vue": "^2.3.1",
    "typescript": "~4.6.3",
    "vite": "^2.9.1",
    "vue-tsc": "^0.33.9"
}

错误:/bin/sh:1:vue-tsc:找不到

我的猜测是客户端上的 devDepentencies 没有被获取。但是我没有将 node_env 设置为 production ,因此不知道为什么没有获取它们。

将所有 DevDepentencies 移动到依赖项一个好主意?

My folder structure:

folder structure

My scripts:

"scripts": {
    "start": "node main.mjs",
    "dev": "NODE_ENV='development' npx nodemon main.mjs",
    "build": "cd client && yarn build",
    "install-client": "cd client && yarn",
    "heroku-postbuild": "yarn install-client && yarn build"
  }

client/package.json

"dependencies": {
    ...
},
"devDependencies": {
    ...
    "@vitejs/plugin-vue": "^2.3.1",
    "typescript": "~4.6.3",
    "vite": "^2.9.1",
    "vue-tsc": "^0.33.9"
}

The error: /bin/sh: 1: vue-tsc: not found

My guess is that devDependencies on the client side aren't being fetched. But I did not set NODE_ENV to production so no idea why they aren't being fetched.

Is moving all the devDependencies to dependencies a good idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不再见 2025-02-06 12:05:19

这很可能是由两个问题之一引起的:

  • Heroku正在修剪生产应用程序的DevDecties
  • Heroku正在缓存以前构建中的Node_modules,

以便为应用程序创建一个较小的slug slug尺寸,而Heroku的buildpack会从包装中删除DevDependencies。构建的结尾,以便SLUG仅包括在运行时列出的依赖项。

禁用此依赖项修剪,

heroku config:set NPM_CONFIG_PRODUCTION=false

您可以通过运行:或,对于纱线来

heroku config:set YARN_PRODUCTION=false

但是如果是这种情况,并且在运行时也使用丢失的依赖项,则应在依赖项而不是下列出。 DevDepentencies


Heroku,默认情况下使用 NPM CI 而不是 npm i 。因此,另一个选项是通过:

heroku config:set USE_NPM_INSTALL=true

禁用缓存:

heroku config:set NODE_MODULES_CACHE=false

值得检查您已在软件包中指定了正确的npm和node版本。并且您已承诺 package-lock.json yarn.lock

This is likely caused by one of two issues:

  • Heroku is pruning devDependencies from production app
  • Heroku was caching the node_modules from previous build

In order create a smaller slug size for apps, the Heroku's buildpack will prune out the devDependencies from the package.json at the end of the build, so that the slug will only include the dependencies that are listed at runtime.

You can disable this dependency pruning, by running:

heroku config:set NPM_CONFIG_PRODUCTION=false

Or, for Yarn

heroku config:set YARN_PRODUCTION=false

But if this is the case, and the missing dependency is also used at runtime, then it should be listed under dependencies rather than devDependencies.


Heroku, by default uses npm ci instead of npm i. So another option would be to switch this back, with:

heroku config:set USE_NPM_INSTALL=true

And to disable the cache:

heroku config:set NODE_MODULES_CACHE=false

And worth also checking that you've specified the right NPM and Node version in your package.json (under engines). And that you've committed either a package-lock.json or yarn.lock.

浮萍、无处依 2025-02-06 12:05:19

在 @lissy93的解释的灵感中,那些试图用vite将Vue 3应用程序部署到Heroku的人。请按照此处的操作 https://www.codementor.io/@ravianand1988/easily-4-steps-to-countinous-deliver-delivery-auto-auto-auto-deploy-vue-vue-js-js-js-app-onapp-on-heroku-heroku-heroku-heroku-heroku-xljk9777777777pq (忽略 @vue/cli安装和vue-cli-service脚本),然后

NODE_ENV=development, 
NODE_MODULES_CACHE = false

在heroku设置中设置,因为您是从github连接了仓库。然后将其在package.json中的脚本标签中放置,

...
"prestart": "npm run build",
"build": "npx vite build",
"start": "node server.js",
...

然后再次运行您的部署。

With inspiration from @Lissy93's explanation, For those trying to deploy Vue 3 app with Vite to Heroku. Follow the instruction here https://www.codementor.io/@ravianand1988/easily-4-steps-to-continuous-delivery-auto-deploy-vue-js-app-on-heroku-xljk977pq (ignore the @vue/cli install and the vue-cli-service scripts) then set

NODE_ENV=development, 
NODE_MODULES_CACHE = false

in your heroku settings given that you're connecting your repo from github. Then have this in your scripts tag in package.json

...
"prestart": "npm run build",
"build": "npx vite build",
"start": "node server.js",
...

Then run your deployment again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文