为什么可以';我不能让这个应用程序使用webpack和Aweasome typescript loader将typescript文件编译成javascript吗?
我有一个angular 4应用程序,我正在使用webpack和awesome typescript loader将typescript编译成js进行构建。当我为本地运行为什么可以';我不能让这个应用程序使用webpack和Aweasome typescript loader将typescript文件编译成javascript吗?,javascript,angular,typescript,webpack,awesome-typescript-loader,Javascript,Angular,Typescript,Webpack,Awesome Typescript Loader,我有一个angular 4应用程序,我正在使用webpack和awesome typescript loader将typescript编译成js进行构建。当我为本地运行npm run start时,它可以工作,但当我运行npm run build时,它不会将typescript文件编译成js,并且我得到以下错误: ERROR in [at-loader] ./src/components/app.module.ts:21:39 TS2305: Module '"/Users/*****
npm run start
时,它可以工作,但当我运行npm run build
时,它不会将typescript文件编译成js,并且我得到以下错误:
ERROR in [at-loader] ./src/components/app.module.ts:21:39
TS2305: Module '"/Users/*******/Desktop/*****/src/services/index"' has no exported member 'ArticlesService'.
ERROR in [at-loader] ./src/components/app.module.ts:27:10
TS2305: Module '"/Users/********/Desktop/*********/src/services/index"' has no exported member 'StateService'.
ERROR in [at-loader] ./src/components/views/activities/activities.component.ts:22:11
TS6133: 'currViewName' is declared but its value is never read.
ERROR in [at-loader] ./src/components/views/articles/articles.component.ts:23:11
TS6133: 'currViewName' is declared but its value is never read.
ERROR in [at-loader] ./src/components/views/forgot-password/forgot-password.component.ts:229:15
TS6133: 'errorStr' is declared but its value is never read.
ERROR in [at-loader] ./src/components/views/infusion-manager/infusion-manager.component.ts:118:11
TS6133: 'currViewName' is declared but its value is never read.
ERROR in [at-loader] ./src/components/views/profile/profile.component.ts:3:40
TS2305: Module '"/Users/*********/Desktop/**********/src/services/index"' has no exported member 'StateService'.
ERROR in [at-loader] ./src/components/views/profile/profile.component.ts:149:27
TS2339: Property 'updateUserData' does not exist on type 'UserApiService'.
ERROR in [at-loader] ./src/components/views/registration/registration.component.ts:229:43
TS2339: Property 'PATIENT' does not exist on type 'typeof Constants'.
ERROR in [at-loader] ./src/components/views/registration/registration.component.ts:235:24
TS2339: Property 'PATIENT' does not exist on type 'typeof Constants'.
ERROR in [at-loader] ./src/components/views/registration/registration.component.ts:278:25
TS2365: Operator '===' cannot be applied to types 'number' and 'string'.
ERROR in [at-loader] ./src/services/state.service.ts:7:11
TS6133: 'currState' is declared but its value is never read.
Child html-webpack-plugin for "index.html":
[0] ./~/html-webpack-plugin/lib/loader.js!./src/index.html 1.54 kB {0} [built]
factory:377ms building:9ms = 386ms
Child extract-text-webpack-plugin:
[0] ./~/css-loader/lib/css-base.js 2.26 kB {0} [built]
[] -> factory:1ms building:11ms = 12ms
[1] ./src/style/fonts/Roboto-Bold.ttf 46 bytes {0} [built]
[] -> factory:14ms building:1ms = 15ms
[2] ./src/style/fonts/Roboto-Light.ttf 47 bytes {0} [built]
[] -> factory:15ms building:0ms = 15ms
[3] ./src/style/fonts/Roboto-Medium.ttf 48 bytes {0} [built]
[] -> factory:14ms building:1ms = 15ms
[4] ./src/style/fonts/Roboto-Regular.ttf 49 bytes {0} [built]
[] -> factory:14ms building:1ms = 15ms
[5] ./src/style/fonts/Roboto-Thin.ttf 46 bytes {0} [built]
[] -> factory:15ms building:0ms = 15ms
[6] ./~/css-loader!./~/postcss-loader/lib!./~/sass-loader/lib/loader.js!./src/style/app.scss 23.9 kB {0} [built]
factory:3ms building:72ms = 75ms
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! app@0.0.0 build: `rimraf dist && webpack --progress --profile --bail`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the app@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/*********/.npm/_logs/2018-10-04T15_40_20_857Z-debug.log
以下是typescript的webpack.config.js文件:
var atlOptions = '';
if (isTest && !isTestWatch) {
// awesome-typescript-loader needs to output inlineSourceMap for code coverage to work with source maps.
atlOptions = 'inlineSourceMap=true&sourceMap=false';
}
config.module = {
rules: [
// Support for .ts files.
{
test: /\.ts$/,
loaders: ['awesome-typescript-loader?' + atlOptions, 'angular2-template-loader', '@angularclass/hmr-loader'],
exclude: [isTest ? /\.(e2e)\.ts$/ : /\.(spec|e2e)\.ts$/, /node_modules\/(?!(ng2-.+))/]
}
这来自tsconfig.json文件:
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noEmitHelpers": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noStrictGenericChecks": true,
"lib": ["es2015", "dom"]
},
"compileOnSave": false,
"buildOnSave": false,
"awesomeTypescriptLoaderOptions": {
"forkChecker": true,
"useWebpackText": true
}
}
本项目中使用的依赖项有node 8.10.0、npm 6.1.0、webpack 2.6.1、awesome typescript loader 3.1.3、typescript 2.6.1
有什么我遗漏的吗 在本地web包中运行时,不要检查所有可能的错误。若发生错误,只抛出异常(在开发环境中)。但在构建时,请检查运行时可能发生的所有错误。您必须修复这些构建问题并获得良好的构建文件。所有这些问题都是由于typescript没有编译成有效的javascript。编译时出现了一些问题。你是说修复所有错误并不能解决问题吗?对不起,我不知道。还有一些像这样的问题。如果你能从这些方面得到帮助,非常感谢你的回答。将allowSyntheticDefaultImports添加到你的编译器中options@PlayMa256谢谢你的建议。我刚刚添加了它,但仍然出现了这些错误。@PlayMa256我认为这就是问题所在:npm ERR!app@0.0.0build:`rimraf dist&&webpack--progress--profile--bail实际上不是,到处都是打字脚本错误,这就是它被窃听的原因