最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

“意外令牌导入”错误与Angular4 +通用+ NG

运维笔记admin8浏览0评论

“意外令牌导入”错误与Angular4 +通用+ NG

“意外令牌导入”错误与Angular4 +通用+ NG

所以我升级到角4+只是让我可以利用通用软件包服务器端渲染引擎优化的目的。我实现了,在我现有的角度2+项目通过将其升级到角4+和。

只有一个区别,我使用NG-引导(V1.0.0-alpha.22)。但是,当我使用NPM运行启动-U-dev的运行的节点服务器我得到这个错误在NG-引导进口的关键字。


[email protected] start-u-dev /Users/giric/Projects/apnaDoctor/webapp/appUI  
ts-node src/server.ts  

/appUI/node_modules/@ng-bootstrap/ng-bootstrap/accordion/accordion.module.js:1
(function (exports, require, module, __filename, __dirname) { import { NgModule } from '@angular/core';  
                                                              ^^^^^^  
SyntaxError: Unexpected token import  
    at createScript (vm.js:53:10)  
    at Object.runInThisContext (vm.js:95:10)  
    at Module._compile (module.js:543:28)  
    at Object.Module._extensions..js (module.js:580:10)  
    at Module.load (module.js:488:32)  
    at tryModuleLoad (module.js:447:12)  
    at Function.Module._load (module.js:439:3)  
    at Module.require (module.js:498:17)  
    at require (internal/module.js:20:19)  
    at Object.<anonymous> (/appUI/dist/ngfactory/src/app/app.server.module.ngfa
ctory.ts:18:1)  
    at Module._compile (module.js:571:32)  
    at Module.m._compile (/appUI/node_modules/ts-node/src/index.ts:406:23)  
    at Module._extensions..js (module.js:580:10)  
    at Object.require.extensions.(anonymous function) [as .ts]
(/webapp/appUI/node_mod
ules/ts-node/src/index.ts:409:12)  
    at Module.load (module.js:488:32)  

pm ERR! Darwin 16.6.0  
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "start-u-dev"  
npm ERR! node v7.7.4  
npm ERR! npm  v4.1.2  
npm ERR! code ELIFECYCLE  
npm ERR! [email protected] start-u-dev: `ts-node src/server.ts`  
npm ERR! Exit status 1  
npm ERR!  
npm ERR! Failed at the [email protected] start-u-dev script 'ts-node src/server.ts'.  
npm ERR! Make sure you have the latest version of node.js and npm installed.  
npm ERR! If you do, this is most likely a problem with the app-ui package,  
npm ERR! not with npm itself.  
npm ERR! Tell the author that this fails on your system:  
npm ERR!     ts-node src/server.ts  
npm ERR! You can get information on how to open an issue for this project with:  
npm ERR!     npm bugs app-ui  
npm ERR! Or if that isn't available, you can get their info via:  
npm ERR!     npm owner ls app-ui  
npm ERR! There is likely additional logging output above.  

npm ERR! Please include the following file with any support request:  

这是我的package.json样子

{  
  "name": "app-ui",  
  "version": "0.0.0",  
  "license": "MIT",  
  "scripts": {  
    "ng": "ng",  
    "start": "ng serve",  
    "build": "ng build",  
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "prestart": "npm install",
    "postinstall": "bower install",
    "prestart-u-dev": "npm install && ng build && ngc",
    "start-u-dev": "ts-node src/server.ts",
    "prestart-u-prod": "npm install && ng build --prod && ngc",
    "start-u-prod": "ts-node src/server.ts"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.0.1",
    "@angular/cli": "^1.0.0-rc.1",
    "@angular/common": "^4.0.1",
    "@angular/compiler": "^4.0.1",
    "@angular/compiler-cli": "^4.0.1",
    "@angular/core": "^4.0.1",
    "@angular/forms": "^4.0.1",
    "@angular/http": "^4.0.1",
    "@angular/platform-browser": "^4.0.1",
    "@angular/platform-browser-dynamic": "^4.0.1",
    "@angular/platform-server": "^4.0.1",
    "@angular/router": "^4.0.1",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.22",
    "angular2-toaster": "^3.0.1",
    "core-js": "^2.4.1",
    "ng2-webstorage": "^1.5.1",
    "rxjs": "^5.1.0",
    "rxjs-es": "^5.0.0-beta.12",
    "typescript": "^2.2.2",
    "ui-router-ng2": "^1.0.0-beta.4",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "@types/jasmine": "2.5.38",
    "@types/node": "~6.0.60",
    "codelyzer": "~2.0.0",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.0.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "node-sass": "^4.5.0",
    "protractor": "~5.1.0",
    "raw-loader": "^0.5.1",
    "sass-loader": "^6.0.3",
    "ts-node": "~2.0.0",
    "tslint": "~4.4.2"
  }
}

更新:此前我删除angular2,烤面包机,但后来我再次添加它只是为了确保它不是抛出同样的错误只是烤面包机模块。事实证明,无论是angular2,烤面包机和NG-引导抛出了同样的错误。

更新2:当我使用NG服务器上运行的服务器,它做工精细,用NG-引导和angular2,烤面包机与角度没有问题4+

有什么建议么?提前致谢。

回答如下:

对于那些试图了解该解决方案是什么,你基本上要使用白名单和angular2-toaster等模块给这个问题。

  1. 如果使用角CLI中,使用ng eject创建webpack.config.js
  2. 通过webpack-node-externals安装npm install依赖,并在webpack.config.js文件中添加以下行 const nodeExternals = require('webpack-node-externals'); module.exports = { ... target: 'node', externals: [nodeExternals({ whitelist: [ /^@ng-bootstrap\/ng-bootstrap/, /^angular2\-toaster/, ] })], ... }
发布评论

评论列表(0)

  1. 暂无评论