为什么我不能使用webpack和awesome typescript loader将这个应用程序文件编译成javascript?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么我不能使用webpack和awesome typescript loader将这个应用程序文件编译成javascript?相关的知识,希望对你有一定的参考价值。
我有一个有角度的4应用程序,我正在使用webpack和awesome typescript loader将Typescript编译为js进行构建。当我运行npm run start
for local时它可以工作但是当我运行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
}
}
此项目中使用的依赖项是节点8.10.0,npm 6.1.0,webpack 2.6.1,awesome-typescript-loader 3.1.3,typescript 2.6.1
有什么东西我遗漏了吗?
在本地Web包中运行时,不检查所有可能的错误。如果发生错误,则抛出异常(在开发环境中)。但在构建它时,请检查运行时可能发生的所有错误。你必须解决这些问题,以便构建和获得良好的构建文件。
以上是关于为什么我不能使用webpack和awesome typescript loader将这个应用程序文件编译成javascript?的主要内容,如果未能解决你的问题,请参考以下文章
将 Font Awesome 与 Webpack 和 ExtractTextPlugin 一起使用
使用 Webpack 2 和 awesome-typescript-loader 的 baseUrl 和路径解析
SCSS Webfont (Font Awesome) 使用 Webpack 编译损坏
在 vue-cli webpack 项目中导入 Font Awesome