从“快递”进口快递;语法错误:意外的标识符

时间:2019-02-12 12:58:45

标签: node.js express import nodemon

我一直在通过教程制作脚本,但是当我尝试通过nodemon运行index.js来运行index.js时,在从'express'指向import express时出现语法错误。 。

我已经安装了nodemon,因为bd我还运行了mongo和mongod。教程可能已过时,或者已安装/正在运行而没有被告知。

我的index.js

import express from 'express';
import dbConfig from './config/db';
const app = express();
dbConfig();
const PORT = process.env.PORT || 3000;
app.listen(PORT, err => {
  if (err) {
    console.error(err);
  }{
    console.log('App listen to port: ${PORT}');
  }
});

package.json:

{
  "name": "meetup-backend",
  "version": "0.0.1",
  "main": "index.js",
  "scripts": {
    "dev": "NODE_ENV=development nodemon dist/index.js",
    "build:watch": "babel -w --out-dir=dist ./src",
    "clean": "rimraf dist",
    "lint": "eslint src",
    "lint:fix": "eslint --fix src"
  },
  "repository": {},
  "author": "Emanuel Quimper",
  "license": "MIT",
  "dependencies": {
    "axios": "^0.16.1",
    "babel-polyfill": "^6.26.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "babel-register": "^6.26.0",
    "body-parser": "^1.18.3",
    "detect-port": "^1.3.0",
    "es6": "0.0.7",
    "express": "^4.16.4",
    "jsonwebtoken": "^7.3.0",
    "mongoose": "4.7.7",
    "morgan": "^1.9.1",
    "passport": "^0.3.2",
    "passport-jwt": "^2.2.1"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-preset-env": "^1.7.0",
    "eslint": "^3.19.0",
    "eslint-config-equimper": "^1.6.2",
    "nodemon": "^1.18.10",
    "rimraf": "^2.6.1"
  }
}

当我运行nodemon index.js时,我得到:

 nodemon index.js
[nodemon] 1.18.10
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
/Users/ari-mikkopenttila/Documents/GitHub/youtubeMeetupAppReactNativeNode/meetup-backend/src/index.js:3
import express from 'express';
       ^^^^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
[nodemon] app crashed - waiting for file changes before starting...

我似乎无法找到导致错误的原因和解决方法。如果问题很容易解决,则需要帮助/建议和道歉。

0 个答案:

没有答案