"Npm Start" 不工作

"Npm Start" Is Not Working

我正在制作一个网站,我使用命令 npm start 将它放在本地主机上。但是,在我在 Visual Studio 代码编辑器上创建两个工作区后,它突然停止工作。它只会给我一个错误。

这是错误的样子:

npm ERR! path C:\Users\audre\first-blog\package.json

npm ERR! code ENOENT

npm ERR! errno -4058

npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\audre\first-blog\package.json'

npm ERR! enoent This is related to npm not being able to find a file.

npm ERR! enoent

npm ERR! A complete log of this run can be found in:

npm ERR! C:\Users\audre\AppData\Roaming\npm-cache_logs18-05-29T07_42_13_915Z-debug.log

我不知道那是什么意思。谁能帮我?谢谢!

编辑: 我的 package.json 文件包含以下内容:

{
  "name": "pug-starter",
  "version": "1.0.0",
  "description": "Simple pug (jade) starter [framework] enabling faster delivery of HTML & CSS projects to a private server and/or automatic deployment of GitHub pages.",
  "main": "index.js",
  "scripts": {
    "dev": "gulp dev",
    "start": "gulp dev",
    "prod": "gulp build --production",
    "deploy": "gulp build --production && gulp deploy && gulp clean:ghpages",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "//": "CUSTOM CONFIGURATION",
  "config": {
    "directory": {
      "development": "tmp",
      "production": "build",
      "ghpages": ".publish",
      "source": "src",
      "data": "_data",
      "component": "_component",
      "layout": "_layout",
      "asset": "_asset",
      "image": "image",
      "font": "font",
      "templateCollection": [
        "article",
        "product"
      ]
    },
    "render": {
      "sourceFileChange": false,
      "url": {
        "//": "this is recommended to avoid Linux/Windows capitalization issue",
        "htmlExtensionOn": false,
        "toLowercase": true
      }
    },
    "entry": {
      "cssExternal": "style**.{scss,sass}",
      "cssInline": "inline**.{scss,sass}",
      "css": {
        "inline": false,
        "external": true
      }
    }
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/marianzburlea/pug-starter.git"
  },
  "keywords": [
    "pug",
    "starter",
    "jade",
    "starter"
  ],
  "author": "Marian Zburlea",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/marianzburlea/pug-starter/issues"
  },
  "homepage": "https://github.com/marianzburlea/pug-starter#readme",
  "devDependencies": {
    "autoprefixer": "^6.7.5",
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.1.2",
    "babel-plugin-add-module-exports": "^0.2.1",
    "babel-preset-env": "^1.6.1",
    "browser-sync": "^2.18.8",
    "eslint": "^3.16.1",
    "foldero": "^0.1.1",
    "gulp": "github:gulpjs/gulp#4.0",
    "gulp-cached": "^1.1.1",
    "gulp-changed": "^2.0.0",
    "gulp-changed-in-place": "^2.2.0",
    "gulp-debug": "^3.1.0",
    "gulp-gh-pages": "^0.5.4",
    "gulp-if": "^2.0.2",
    "gulp-imagemin": "^3.1.1",
    "gulp-inline-source": "^3.0.0",
    "gulp-load-plugins": "^1.5.0",
    "gulp-plumber": "^1.1.0",
    "gulp-postcss": "^6.3.0",
    "gulp-pug": "^3.2.0",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^3.1.0",
    "gulp-sourcemaps": "^2.4.1",
    "imagemin-jpegoptim": "^5.0.0",
    "imagemin-pngquant": "^5.0.0",
    "imagemin-svgo": "^5.2.0",
    "jstransformer-markdown-it": "^2.0.0",
    "merge-stream": "^1.0.1",
    "minimist": "^1.2.0"
  }
}

使用可以保护环境的流程管理器。

几个选项是

永远(https://www.npmjs.com/package/forever)

这样,您可以使用 forever start <mainfilename>

在本地主机上启动网站

PM2 (https://www.npmjs.com/package/pm2)

这样,您可以使用 pm2 start <mainfilename>

在本地主机上启动网站

使用流程管理器,您可以从环境规范中抽象出来,直到您需要更具体的东西。

ENOENT 表示,您所在的位置 运行 npm start 命令目录不包含 package.json 文件。

首先,确保您在正确的目录中并且它有 package.json 个文件。

另外,如果没有package.json文件,可以使用npm init命令初始化。

如果不是这样,请随时发表评论以纠正我。

当所有其他方法都失败时,remove/reinstall node.js 完全。当您在所有节点 env 命令上到处都出现错误时,这意味着节点已损坏或以某种方式出错。

如果您的机器上有多个版本的 nodejs 并且是 运行 节点版本管理器 (nvm),请务必在终端中正确设置您的版本。

例如。 nvm 使用 v9.5.0