运行 npm run compile 时出现 NPM 错误

问题描述

当我运行 npm run comile:js 时,我遇到了这个问题。那该怎么办?

PS C:\Users\Marko\Desktop\storefrontdata-master\storefrontdata-master> npm run compile:js
npm ERR! missing script: compile:js

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Marko\AppData\Roaming\npm-cache\_logs\2021-01-04T11_00_45_777Z-debug.log
PS C:\Users\Marko\Desktop\storefrontdata-master\storefrontdata-master> 

这是我的 package.json 的样子,如果可以的话:

{
  "name": "refarchdata","version": "4.4.1","description": "This is a repository for the data that goes with the ref arch storefront.","main": "","dependencies": {},"devDependencies": {},"scripts": {
    "zipData": "if [ -f demo_data_sfra.zip ] ; then rm -r demo_data_sfra.zip && zip -r demo_data_sfra.zip demo_data_sfra ; else zip -r demo_data_sfra.zip demo_data_sfra ; fi"
  },"repository": {
    "type": "git","url": "git+https://github.com/SalesforceCommerceCloud/storefrontdata.git"
  },"author": "","license": "ISC","homepage": "https://github.com/SalesforceCommerceCloud/storefrontdata"
}

解决方法

错误已经告诉你原因了:

no such file or directory,open 'C:\Users\Marko\Desktop\storefrontdata-master\package.json'

您的项目没有 package.json 文件。请确保你有一个。

在更新后更新:打开 package.json(如果有),然后查找 scripts 并确保 compile:js 在它下面。该文件应如下所示:

// package.json
 {
  .....
 scripts : {
     "compile:js": "....",}
  ....

 }

,

你应该在 package.json 文件中添加一个脚本才能运行 作为这个形状 npm 运行编译 它将检查 package.json 中是否有脚本然后运行它 像这样

{
  //some code
 scripts : {
     "compile:js": "waht you need to put here",}
 

 }

如果你想运行他的名字 compile.js 使用 node 和文件位置的文件 像那样node compile.js