1

私はwebpack 2でAngular 2から始めています.webpackの実行中に以下のエラーに直面しています

WARNING in ./~/@angular/core/@angular/core.es5.js
5870:15-36 Critical dependency: the request of a dependency is an expression

WARNING in ./~/@angular/core/@angular/core.es5.js
5886:15-102 Critical dependency: the request of a dependency is an expression

ERROR in ./app/dashboard/hero-detail.component.css
Module parse failed: D:\WorkSpace\Angular2\Login\app\dashboard\hero-detail.compo
nent.css Unexpected token (1:6)
You may need an appropriate loader to handle this file type.
| label {
|   display: inline-block;
|   width: 3em;
 @ ./app/dashboard/hero-detail.component.ts 45:17-55
 @ ./app/dashboard/index.ts
 @ ./app/app.module.ts
 @ ./app/main.ts

ERROR in ./app/dashboard/dashboard.component.css
Module parse failed: D:\WorkSpace\Angular2\Login\app\dashboard\dashboard.compone
nt.css Unexpected token (1:6)
You may need an appropriate loader to handle this file type.
| [class*='col-'] {
|   float: left;
|   padding-right: 20px;
 @ ./app/dashboard/dashboard.component.ts 32:17-53
 @ ./app/dashboard/index.ts
 @ ./app/app.module.ts
 @ ./app/main.ts

ERROR in ./app/dashboard/heroes.component.css
Module parse failed: D:\WorkSpace\Angular2\Login\app\dashboard\heroes.component.
css Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| .selected {
|   background-color: #CFD8DC !important;
|   color: white;
 @ ./app/dashboard/heroes.component.ts 65:17-50
 @ ./app/dashboard/index.ts
 @ ./app/app.module.ts
 @ ./app/main.ts

ERROR in ./app/dashboard/hero-search.component.css
Module parse failed: D:\WorkSpace\Angular2\Login\app\dashboard\hero-search.compo
nent.css Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| .search-result{
|   border-bottom: 1px solid gray;
|   border-left: 1px solid gray;
 @ ./app/dashboard/hero-search.component.ts 59:17-55
 @ ./app/dashboard/index.ts
 @ ./app/app.module.ts
 @ ./app/main.ts
Child html-webpack-plugin for "index.html":
       [0] ./~/html-webpack-plugin/lib/loader.js!./index.html 341 bytes {0} [built]

以下は私のpackage.jsonです

  "devDependencies": {
    "@types/core-js": "^0.9.41",
    "@types/jasmine": "2.5.36",
    "@types/node": "^6.0.45",
    "angular2-template-loader": "^0.6.0",
    "awesome-typescript-loader": "^3.0.4",
    "css-loader": "^0.28.0",
    "extract-text-webpack-plugin": "^2.1.0",
    "file-loader": "^0.9.0",
    "html-loader": "^0.4.5",
    "html-webpack-plugin": "^2.16.1",
    "jasmine-core": "^2.4.1",
    "karma": "^1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-jasmine": "^1.0.2",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "^2.0.1",
    "null-loader": "^0.1.1",
    "postcss-cssnext": "^2.10.0",
    "postcss-loader": "^1.3.3",
    "postcss-responsive-type": "^0.5.1",
    "postcss-smart-import": "^0.6.12",
    "raw-loader": "^0.5.1",
    "resolve-url-loader": "^2.0.2",
    "rimraf": "^2.5.2",
    "sass-loader": "^6.0.3",
    "style-loader": "^0.13.1",
    "stylus-loader": "^3.0.1",
    "to-string-loader": "^1.1.5",
    "typescript": "^2.0.9",
    "webpack": "2.2.1",
    "webpack-dev-server": "2.4.1",
    "webpack-merge": "^3.0.0"
  }

これは私のwebpack.config.jsです

var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var path = require('path');

module.exports = {
    entry: {
        'app': './app/main.ts',
        'vendor': './vendor.ts'
    },
    output: {
        filename: "[name].js",
        path: path.resolve(__dirname, 'dist')
    },
    resolve: {
        extensions: ['.ts', '.js']
    },

    module: {
        rules: [
            {
                test: /\.ts$/,
                loaders: ['awesome-typescript-loader', 'angular2-template-loader']
            },
            {
                test: /\.html$/,
                use: [{
                    loader: 'html-loader',
                    options: {
                        minimize: true
                    }
                }],
            },
            {
                test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
                loader: 'file-loader?name=assets/[name].[hash].[ext]'
            },
            {
                test: /\.css$/,
                include: /app(\/|\\)css/,
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: "css-loader"
                })
            }
        ]
    },

    plugins: [
        // Workaround for angular/angular#11580
        new webpack.ContextReplacementPlugin(
            // The (\\|\/) piece accounts for path separators in *nix and Windows
            /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
            'app', // location of your src
            {} // a map of your routes
        ),

        new webpack.optimize.CommonsChunkPlugin({
            name: 'vendor'
        }),

        new HtmlWebpackPlugin({
            template: './index.html'
        }),
        new ExtractTextPlugin("bundle.css")
    ]
};

CSS ローダーのインクルードを削除すると、ビルドは成功しますが、URL にアクセスしているときに別のエラーに直面しています

Uncaught Error: Expected 'styles' to be an array of strings.
    at assertArrayOfStrings (http://127.0.0.1:8080/vendor.js:30661:19) [<root>]
    at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (http://127.0.0.1:8080/vendor.js:41563:13) [<root>]
    at CompileMetadataResolver._getEntryComponentMetadata (http://127.0.0.1:8080/vendor.js:42265:45) [<root>]
    at http://127.0.0.1:8080/vendor.js:42251:48 [<root>]
    at Array.forEach (native) [<root>]
    at CompileMetadataResolver._getEntryComponentsFromProvider (http://127.0.0.1:8080/vendor.js:42250:30) [<root>]
    at http://127.0.0.1:8080/vendor.js:42214:83 [<root>]
    at Array.forEach (native) [<root>]
    at CompileMetadataResolver._getProvidersMetadata (http://127.0.0.1:8080/vendor.js:42178:19) [<root>]
    at http://127.0.0.1:8080/vendor.js:42180:23 [<root>]
    at Array.forEach (native) [<root>]
    at CompileMetadataResolver._getProvidersMetadata (http://127.0.0.1:8080/vendor.js:42178:19) [<root>]
    at http://127.0.0.1:8080/vendor.js:41753:63 [<root>]
    at Array.forEach (native) [<root>]

多くの人がこの問題に直面しているようですが、彼らの解決策は私にとってはうまくいきました.どこが間違っているのでしょうか?

4

1 に答える 1