【问题标题】:react-scrips: not found - Azure DevOps build pipeline反应脚本:未找到 - Azure DevOps 构建管道
【发布时间】:2020-11-17 15:52:09
【问题描述】:

我正在尝试在 Azure DevOps 中为我的 create-react-app 项目创建构建管道。但是,当我运行它时,我在 npm 安装和构建作业期间收到以下错误消息。

2020-11-16T16:38:47.9641910Z npm ERR! Only absolute URLs are supported

2020-11-16T16:38:47.9906864Z 
2020-11-16T16:38:47.9908747Z npm ERR! A complete log of this run can be found in:

2020-11-16T16:38:47.9910292Z npm ERR!     /home/vsts/.npm/_logs/2020-11-16T16_38_47_983Z-debug.log

2020-11-16T16:38:48.2879019Z 
2020-11-16T16:38:48.2879989Z > allpointsui@1.0.0 build /home/vsts/work/1/s

2020-11-16T16:38:48.2881040Z > react-scripts build
2020-11-16T16:38:48.2881441Z 

2020-11-16T16:38:48.2927383Z sh: 1: react-scripts: not found

2020-11-16T16:38:48.2967162Z npm ERR! code ELIFECYCLE

2020-11-16T16:38:48.2968631Z npm ERR! syscall spawn

2020-11-16T16:38:48.2969062Z npm ERR! file sh

2020-11-16T16:38:48.2971442Z npm ERR! errno ENOENT

2020-11-16T16:38:48.2983381Z npm ERR! allpointsui@1.0.0 build: `react-scripts build`

2020-11-16T16:38:48.2983876Z npm ERR! spawn ENOENT
2020-11-16T16:38:48.2984513Z npm ERR! 

2020-11-16T16:38:48.2984827Z npm ERR! Failed at the allpointsui@1.0.0 build script.

2020-11-16T16:38:48.2985278Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

2020-11-16T16:38:48.3029598Z 
2020-11-16T16:38:48.3032027Z npm ERR! A complete log of this run can be found in:

2020-11-16T16:38:48.3033461Z npm ERR!     /home/vsts/.npm/_logs/2020-11-16T16_38_48_298Z-debug.log

2020-11-16T16:38:48.3150378Z ##[error]Bash exited with code '1'.

2020-11-16T16:38:48.3205602Z ##[section]Finishing: npm install and build

这是我的管道 YAML 文件。

trigger:
-master

pool:
`vmImage: 'ubuntu-latest`

steps:
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'

- script: |
npm install
npm run build
displayName: 'npm install and build'

- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true


- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'

为了解决这个错误,我尝试过安装 react-scripts4.0 的 npm i 和 npm audit fix,但错误仍然存​​在。我还看到很多人在其他帖子中建议删除 package-lock.json,但我们不希望这样做。还有一点需要注意的是:我可以在本地计算机上成功运行项目的构建。有关如何解决此问题的任何建议或想法?提前谢谢!

【问题讨论】:

    标签: azure-devops azure-pipelines create-react-app react-scripts


    【解决方案1】:

    react-scrips:未找到 - Azure DevOps 构建管道

    首先,尝试检查Azure repo中是否存在node_modules目录,如果存在,将其删除,然后运行npm install and build。

    其次,在package.json中添加整个路径来调用react-scripts:

    "start": "node_modules/react-scripts/bin/react-scripts.js start"
    

    而不仅仅是:"start": "react-scripts start"

    如果以上内容无法解决您的问题,请尝试在您的问题中分享您的package.json

    【讨论】:

    • 谢谢,这并没有完全解决它,但它是问题之一。我们已经解决了!
    猜你喜欢
    • 2021-01-21
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 2020-01-30
    • 1970-01-01
    相关资源
    最近更新 更多