这是我的tsconfig.js
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"target": "es5",
"module": "system",
"noImplicitAny": false,
"outDir": "built",
"rootDir": ".",
"sourceMap": false
},
"exclude": [
"node_modules"
]
}
我正在使用tsc
命令将'hello-angular.ts'转换为'hello-angular.js'。并按System.import ('built/hello-angular')
当我启动服务器时,我在浏览器中出错了
Unable to dynamically transpile ES module A loader plugin needs to be configured via
SystemJS.config({transpiler:'transpiler-module'})``
我不明白,为什么systemjs试图转换es5文件..我设置了system.config({transpiler:false}),但它没有帮助..
答案 0 :(得分:2)
您需要添加一个转发器,如以下答案中所述:
Angular 2 - Unable to dynamically transpile ES module, angular2-google-map-auto-complete
在我看来,这在systemjs.config.js中是这样的:
map: {
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build': 'npm:systemjs-plugin-babel/systemjs-babel-browser.js'
},
transpiler: 'plugin-babel',
答案 1 :(得分:0)
我在其中一个插件上遇到同样的错误:
错误:无法动态转换ES模块
需要通过SystemJS.config({ transpiler: 'transpiler-module' })
配置加载程序插件。
实例化http://localhost:62362/node_modules/angular-star-rating/index.js
通过在systemjs.config.js中替换此行来解决此错误:
'angular-star-rating': { defaultExtension: 'js', main: 'index.js' }
这一行:
'angular-star-rating': { defaultExtension: 'js', main: 'angular-star-rating.umd.js' }
答案 2 :(得分:-1)
在tsconfig.json中尝试以下内容:
"module": "commonjs",