【问题标题】:Error: Couldn't find preset "env" relative to directory错误:找不到相对于目录的预设“env”
【发布时间】:2018-07-06 16:46:20
【问题描述】:
  {
  "name": "package.js",
  "version": "1.0.0",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "babel-watch server.js"
  },
  "dependencies": {
    "babel-core": "^6.26.3",
    "expo": "^26.0.0",
    "react": "16.3.0-alpha.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-26.0.0.tar.gz"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-react": "^6.24.1",
    "babel-watch": "^2.0.7"
  },
  "depencies": {
    "apollo-server-express": "^1.3.2",
    "express": "^4.16.2",
    "graphql": "^0.13.0",
    "graphql-tools": "^2.20.2"
  }
}

执行 npm run dev 后显示的错误。错误日志贴在下面。我对 GraphQL、Apollo 和 Angular 还很陌生。

20 error code ELIFECYCLE
21 error errno 1
22 error backend@1.0.0 dev: `babel-watch server.js`
22 error Exit status 1
23 error Failed at the backend@1.0.0 dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

如果我缺少任何其他文件,请随时在 cmets 中询问。

Server.Js

import express from 'express';
import bodyParser from 'body-parser';
import { graphqlExpress } from 'apollo-server-express';

const app = express();

app.get('/', (req, res) => res.send('Hello World'));

app.listen(4000, () => console.log('Express server running on port 4000'));

【问题讨论】:

  • 解释一下你想用代码实现什么
  • @lbo 我正在尝试在执行命令 npm run dev 后在 localhost:4000 上显示“hello world”

标签: angularjs babeljs apollo-server


【解决方案1】:

好像没有babel-preset-env这个包,用npm install babel-preset-env安装就好了。

如果这不能解决问题,可能是因为您在不同的命令行中有另一个 npm 实例。检查是否有任何其他 npm 在同一端口运行。 同时删除node_modules 并清理缓存npm cache clean,然后重新安装您的节点模块(npm install)。

【讨论】:

    猜你喜欢
    • 2019-08-15
    • 1970-01-01
    • 2018-12-15
    • 2020-07-21
    • 2016-11-23
    • 2019-05-31
    • 2018-04-08
    • 2018-01-26
    相关资源
    最近更新 更多