Lerna时在Heroku上Vue构建失败"/>
使用Lerna时在Heroku上Vue构建失败
[试图在Heroku上托管带有Express后端+ Vue前端的Lerna monorepo。组件分别包含在/packages/server
和/packages/frontend
内部。目的是在部署期间构建Vue前端,并通过Express将其作为静态内容托管。
./ package.json
{
"name": "my_app",
"private": true,
"scripts": {
"bootstrap": "lerna bootstrap",
"start": "lerna run start --stream",
"postinstall": "npm run bootstrap",
"build": "lerna run build --stream"
},
"devDependencies": {
"lerna": "^3.20.2"
}
}
我的构建阶段由于失败
lerna notice cli v3.20.2
lerna info Executing command in 2 packages: "npm run build"
frontend: > [email protected] build /tmp/build_c2cbb32af790fe0e5e4852ce2bcab8e0/packages/frontend
frontend: > vue-cli-service build
frontend: sh: 1: vue-cli-service: not found
frontend: npm ERR! code ELIFECYCLE
frontend: npm ERR! syscall spawn
frontend: npm ERR! file sh
frontend: npm ERR! errno ENOENT
frontend: npm ERR! [email protected] build: `vue-cli-service build`
frontend: npm ERR! spawn ENOENT
一个独立的Vue存储库不会以这种方式使其构建阶段失败,因此问题很可能是lerna bootstrap
或Heroku如何构建问题的原因,但是我一直无法弄清楚问题是什么。
create-react-app的类似设置不会失败,可能是由于react-scripts
是常规依赖项。
Lerna和devDependencies是否缺少某些陷阱,还是Vue存在问题?
回答如下:几天后,我终于弄清了设置的问题。问题有两个:
首先,似乎[email protected]可能存在问题,因为即使启动一个独立项目也无法使用NODE_ENV=production
进行构建,因为所有必需的依赖项都包含在devDependencies中。
npx @vue/cli create test
cd test
export NODE_ENV=production
npm install
npm run build
对于本地开发,lerna bootstrap
符合预期,甚至安装了devDependencies。但是,当将其作为CI运行时,将跳过devDependencies。
关于为什么独立的Vue项目在Heroku上构建而没有任何问题,这在nodejs buildpack documentation中有详细说明,>
默认情况下,Heroku将安装package.json中列出的所有依赖项,分别位于依赖项和devDependencies下。
buildpack仅适用于单层软件包,因此,一旦您将软件包嵌套在monorepo布局中,就不会碰到嵌套的devDependencies。
将Vue依赖项从devDependencies中移除现在解决了我的构建问题。
更多推荐
使用Lerna时在Heroku上Vue构建失败
发布评论