Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js “错误”;意外令牌导入“;当你试着跑的时候_Node.js_Angular_Typescript_Angular Universal - Fatal编程技术网

Node.js “错误”;意外令牌导入“;当你试着跑的时候

Node.js “错误”;意外令牌导入“;当你试着跑的时候,node.js,angular,typescript,angular-universal,Node.js,Angular,Typescript,Angular Universal,我试图产生一个角度通用,但我遇到了“ts node server.ts”的问题。输出记录如下: $ npm run start > prestart public-site > ng build --prod && ngc 12% building modules 24/32 modules 8 active ...lic-site/src/styles.scssNode#moveTo was deprecated. Use Container#append.

我试图产生一个角度通用,但我遇到了“ts node server.ts”的问题。输出记录如下:

$ npm run start

> prestart public-site
> ng build --prod && ngc

 12% building modules 24/32 modules 8 active ...lic-site/src/styles.scssNode#moveTo was deprecated. Use Container#append.
Hash:                                                               
Time: 76999ms
chunk    {0} 0.chunk.js 11.9 kB {1} {2} {3} {4} {5} {6} 
chunk   {14} inline.bundle.js (inline) 0 bytes

> start public-site
> ts-node src/server.ts

public-site/node_modules/md2/module.js:7
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> (public-site/src/app/app.module.ts:11:1)

npm ERR! Darwin 16.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "start"
npm ERR! node v7.10.0
npm ERR! npm  v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! start: `ts-node src/server.ts`
npm ERR! Exit status 1
npm ERR! 
$npm运行开始
>启动前公共站点
>ng构建--产品和ngc
12%的构建模块24/32模块8活动…lic site/src/styles.scssNode#moveTo已被弃用。使用容器#append。
搞砸:
时间:76999ms
chunk{0}0.chunk.js 11.9kb{1}{2}{3}{4}{5}{6}
chunk{14}inline.bundle.js(inline)0字节
>启动公共站点
>ts节点src/server.ts
公共站点/node_modules/md2/module.js:7
从“@angular/core”导入{NgModule};
^^^^^^
SyntaxError:意外的令牌导入
在createScript上(vm.js:53:10)
在Object.runInThisContext(vm.js:95:10)
在模块处编译(Module.js:543:28)
在Object.Module.\u extensions..js(Module.js:580:10)
在Module.load(Module.js:488:32)
在tryModuleLoad时(module.js:447:12)
在Function.Module.\u加载(Module.js:439:3)
at Module.require(Module.js:498:17)
根据需要(内部/module.js:20:19)
反对。(公共站点/src/app/app.module.ts:11:1)
npm错误!达尔文16.5.0
npm错误!argv“/usr/local/bin/node”“/usr/local/bin/npm”“运行”“启动”
npm错误!节点v7.10.0
npm错误!npm v4.2.0
npm错误!代码失效循环
npm错误!错误1
npm错误!start:`ts node src/server.ts`
npm错误!退出状态1
npm错误!

如果您知道如何解决此问题,将不胜感激。

所有3d party LIB都应传输。ts节点不传输es2015模块。我使用网页包来传输模块,如@angular/material和@ngx translate。请看我的存储库中的示例:


我希望这能对你有所帮助。

这只是给将来访问的人的一个提示(就像我一样),hammerjs和jquery会导致问题,hammerjs是流行素材库2的一部分,所以这是进行这种转换的人的常见问题

到了最坏的时候,你可以取出第三方lib,一个接一个地重新添加它们,然后每次启动服务器,看看它是否工作

您还可以限制在浏览器中呈现某个对象时调用该对象的时间,就像这样

import { PLATFORM_ID } from '@angular/core';
 import { isPlatformBrowser, isPlatformServer } from '@angular/common';

 constructor(@Inject(PLATFORM_ID) private platformId: Object) { ... }

 ngOnInit() {
   if (isPlatformBrowser(this.platformId)) {
      // Client only code.
      ...
   }
   if (isPlatformServer(this.platformId)) {
     // Server only code.
     ...
   }
 }
-此处找到的通用启动器摘录:


因此,如果您需要使用jquery,请确保您所做的任何调用都在“isPlatformBrowser”中,因为jquery和其他类似的lib使用DOM,而DOM在节点后端不存在,因此会导致错误。

谢谢,这可以为我提供更好的指导