我正在使用带有一些包的lerna:
packages
- server
- authenticator
- graphql
server
是我当前的项目,authenticator
和graphql
是导入的模块。
以下是我的server
package.json
:
{
"name": "@monorepo/server",
"version": "3.0.0",
"private": true,
"scripts": {
"start": "nodemon --exec \"cd ./src && babel-node server.js",
"lint": "eslint ."
},
"dependencies": {
"@monorepo/authenticator": "3.0.0",
"@monorepo/graphql": "3.0.0",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-3": "^6.24.1",
"bcryptjs": "^2.4.3",
"body-parser": "^1.17.2",
"connect-mongo": "^2.0.0",
"crypto": "^1.0.1",
"express": "^4.15.3",
"jwt-simple": "^0.5.1",
"mongoose": "^5.0.10",
"morgan": "^1.8.2",
"nodemailer": "^4.6.0",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"path": "^0.12.7",
"validator": "^9.1.1"
}
}
我的src/server.js
文件:
import express from "express";
import appGraphQL from "@monorepo/graphql/src";
import * as authenticator from "@monorepo/authenticator";
const app = express();
app.listen(3000, () => {
console.log(`Find the server at: http://localhost:3000`);
});
我的graphql/src/index
。js:
import graphqlHTTP from "express-graphql";
... some stuff here...
我的authenticator/src/index.js
:
import passport from "passport";
import passportJWT from "passport-jwt";
import jwt from "jwt-simple";
import bcrypt from "bcryptjs";
import crypto from "crypto";
import mongoose from "mongoose";
... some stuff here...
运行时
$ yarn start
import passport from "passport";
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at loader (D:\monorepo\node_modules\babel-register\lib\node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (D:\monorepo\node_modules\babel-register\lib\node.js:154:7)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (D:/monorepo/packages/pageserver/src/server.js:24:1)
at Module._compile (module.js:570:32)
at loader (D:\monorepo\node_modules\babel-register\lib\node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (D:\monorepo\node_modules\babel-register\lib\node.js:154:7)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
无法理解为什么babel-node会转发graphql
包并且不会转发authenticator
包。
这是babel节点中的错误吗?我在这里缺少什么?
PS:Laravel内部使用符号链接到模块。我使用的是Windows 10。