简体   繁体   English

app.bundle.js angular2中意外的令牌导入

[英]Unexpected token import in app.bundle.js angular2

I'm trying to build an Angular 2 app from scratch with Webpack. 我正在尝试使用Webpack从头开始构建Angular 2应用程序。 After adding all the files and finishing all the configurations, i build the project. 添加所有文件并完成所有配置后,我将构建项目。 while building it didn't give any error. 在构建时没有给出任何错误。 but when i open the index.html the text loads while giving an error in the console as "Uncaught SyntaxError: Unexpected token import in app.bundle.js:47" 但是当我打开index.html时,文本加载时在控制台中给出错误,提示为“ Uncaught SyntaxError:app.bundle.js中意外的令牌导入:47”

this is the place where it results the import error 这是导致导入错误的地方

/***/ function(module, exports) {

    import 'core-js'; **//this is line 47**
    import 'reflect-metadata';
    import 'zone.js/dist/zone';

    import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
    import { AppModule }              from './app.module';

    platformBrowserDynamic().bootstrapModule(AppModule);

/***/ }
/******/ ]);

the repo of my project enter link description here 我项目的仓库在这里输入链接描述

Any reason why im getting this error?.I've tried almost everyting 我收到此错误的任何原因吗?我几乎尝试过一切

You have a typo in your webpack.config.js which caused webpack to not use any loaders and simply concatenate the raw typescript source files into the bundle. 您的webpack.config.js有一个错字,这导致webpack不使用任何加载程序,而只是将原始打字稿源文件连接到包中。

The property is module.loaders not module.loader . 该属性是module.loaders而不是module.loader

You will need something like 您将需要类似

resolve: {
    extensions: ['', '.ts', '.js'],

    root: path.resolve('src')
}

where path is imported with const path = require('path'); const path = require('path');导入const path = require('path'); I don't know why it doesn't infer paths from the working directory... 我不知道为什么它不能从工作目录中推断出路径...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM