bitbucket 管道中缺少包

问题描述 投票:0回答:1

大家好。我正在尝试为我的 nextjs 项目创建一个管道,但遇到了一些问题

我有一个特殊的函数来生成buildId

# scripts/generate-build-id.js

const nextBuildId = require('next-build-id')
const path = require('path');

const generateBuildId = async () => {
    const isDev = [process.env.APP_ENV, process.env.NODE_ENV].some(setting => setting && setting !== 'production');
    return nextBuildId({ dir: path.join(__dirname, '..') })
        .then(BUILD_ID => `${isDev ? 'dev' : 'prod'}_${BUILD_ID}`);
}

module.exports = { generateBuildId };

我在下一个配置中使用它

# next.config.js
const { generateBuildId } = require('./scripts/generate-build-id');

module.exports = {
  ...
  generateBuildId: async () => generateBuildId(),
  ...
};

一切都好。项目运行良好,构建良好等等。

但是如果我尝试使用 bitbucket 的管道部署我的项目,我会收到错误:

非常简单的管道配置

image: node:18

pipelines:
  default:
    - step:
        name: Install dependencies
        caches:
          - node
        script:
          - yarn install
    - step:
        name: Build
        caches:
          - node
        script:
          - yarn build

但是构建步骤返回错误

 + yarn build
yarn run v1.22.19
$                        yarn clear
$ rm -rf .next
$       next build
error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
> Build error occurred
Error: Cannot find module 'next-build-id'
Require stack:
 + /opt/atlassian/pipelines/agent/build/scripts/generate-build-id.js

当然这个包包含在我的 package.json 中。它在本地安装得很好,但在 bitbucket 的机器上安装得不好

我不知道为什么会这样 我尝试了很多npm install、yarn install的组合。尝试添加

yarn add next-build-id
安装软件包步骤,但无论如何都会发生此错误

javascript node.js next.js bitbucket-pipelines yarn-v2
1个回答
0
投票

这真是一个愚蠢的错误:我只需要清除管道中的节点缓存

© www.soinside.com 2019 - 2024. All rights reserved.