Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 为什么因果报应忽视我的打字?_Typescript_Webpack_Karma Runner - Fatal编程技术网

Typescript 为什么因果报应忽视我的打字?

Typescript 为什么因果报应忽视我的打字?,typescript,webpack,karma-runner,Typescript,Webpack,Karma Runner,我尝试为我的React应用程序设置Karma。我的堆栈如下所示: const karma = (config: any) => { config.set({ basePath: '', browsers: ['ChromeHeadless'], frameworks: ['mocha'], files: ['test/actions/errorTests.ts'], preprocessors: {

我尝试为我的React应用程序设置Karma。我的堆栈如下所示:

const karma = (config: any) => {
    config.set({
        basePath: '',
        browsers: ['ChromeHeadless'],
        frameworks: ['mocha'],
        files: ['test/actions/errorTests.ts'],
        preprocessors: {
            'test/actions/errorTests.ts': ['webpack']
        },

        webpack: {
            entry: ['./src/main.tsx'],

            resolve: {
                extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js']
            },

            module: {
                rules: [
                    {
                        test: /\.tsx?$/,
                        exclude: '/node_modules/',
                        use: 'awesome-typescript-loader'
                    }, {
                        test: /\.scss$/,
                        exclude: '/node_modules/',
                        use: [{
                            loader: 'style-loader'
                        }, {
                            loader: 'typings-for-css-modules-loader',
                            options: {
                                modules: true,
                                namedExport: true,
                                sass: true
                            }
                        }, {
                            loader: 'sass-loader',
                            query: {
                                sourceMap: true
                            }
                        }]
                    }
                ]
            }
        },
        webpackMiddleware: {
            noInfo: true
        }
    });
};

export = karma;
  • 业力
  • 反应
  • 网页包
  • 打字稿
对于我的React应用程序,我需要一些自定义打字(
src/typings.d.ts
):

我的
karma.conf.ts
如下所示:

const karma = (config: any) => {
    config.set({
        basePath: '',
        browsers: ['ChromeHeadless'],
        frameworks: ['mocha'],
        files: ['test/actions/errorTests.ts'],
        preprocessors: {
            'test/actions/errorTests.ts': ['webpack']
        },

        webpack: {
            entry: ['./src/main.tsx'],

            resolve: {
                extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js']
            },

            module: {
                rules: [
                    {
                        test: /\.tsx?$/,
                        exclude: '/node_modules/',
                        use: 'awesome-typescript-loader'
                    }, {
                        test: /\.scss$/,
                        exclude: '/node_modules/',
                        use: [{
                            loader: 'style-loader'
                        }, {
                            loader: 'typings-for-css-modules-loader',
                            options: {
                                modules: true,
                                namedExport: true,
                                sass: true
                            }
                        }, {
                            loader: 'sass-loader',
                            query: {
                                sourceMap: true
                            }
                        }]
                    }
                ]
            }
        },
        webpackMiddleware: {
            noInfo: true
        }
    });
};

export = karma;
当我运行
karma start--single run
时,我得到以下输出:

$ karma start --single-run

[at-loader] Using typescript@2.5.2 from typescript and "tsconfig.json" from /Users/rbu0374/Development/octodent/octodent.git/client/tsconfig.json.


[at-loader] Checking started in a separate process...

[at-loader] Ok, 0.721 sec.

[at-loader] Checking started in a separate process...

[at-loader] Checking finished with 4 errors
Hash: 22917d06732ce0b1f6aa
Version: webpack 3.6.0
Time: 2234ms
                     Asset     Size  Chunks                    Chunk Names
                      main  1.29 MB       0  [emitted]  [big]  main
test/actions/errorTests.ts   344 kB       1  [emitted]  [big]  test/actions/errorTests.ts
   [4] ./node_modules/react/react.js 56 bytes {0} [built]
  [20] ./node_modules/react-intl/lib/index.es.js 51.2 kB {0} [built]
  [28] ./node_modules/redux/es/index.js 1.08 kB {0} [built]
  [30] ./src/constants/actions.ts 399 bytes {0} {1} [built]
  [78] ./node_modules/history/es/index.js 460 bytes {0} [built]
 [151] ./src/actions/error.ts 307 bytes {0} {1} [built]
 [154] multi ./src/main.tsx 28 bytes {0}
 [155] ./src/main.tsx 2.04 kB {0} [built]
 [310] ./node_modules/redux-persist/es/index.js 1.7 kB {0} [built]
 [316] ./node_modules/redux-persist/es/integration/react.js 3.41 kB {0} [built]
 [317] ./node_modules/redux-persist/es/storage/index.js 362 bytes {0} [built]
 [320] ./src/reducers/index.ts 471 bytes {0} [built]
 [324] ./src/containers/app/index.tsx 2.85 kB {0} [built]
 [408] ./test/actions/errorTests.ts 533 bytes {1} [built]
 [409] ./node_modules/chai/index.js 40 bytes {1} [built]
    + 417 hidden modules

ERROR in [at-loader] ./src/main.tsx:10:44 
    TS7016: Could not find a declaration file for module 'redux-persist'. '/Users/rbu0374/Development/octodent/octodent.git/client/node_modules/redux-persist/lib/index.js' implicitly has an 'any' type.
  Try `npm install @types/redux-persist` if it exists or add a new declaration (.d.ts) file containing `declare module 'redux-persist';`

ERROR in [at-loader] ./src/main.tsx:11:27 
    TS7016: Could not find a declaration file for module 'redux-persist/es/integration/react'. '/Users/rbu0374/Development/octodent/octodent.git/client/node_modules/redux-persist/es/integration/react.js' implicitly has an 'any' type.
  Try `npm install @types/redux-persist/es/integration/react` if it exists or add a new declaration (.d.ts) file containing `declare module 'redux-persist/es/integration/react';`

ERROR in [at-loader] ./src/main.tsx:12:21 
    TS7016: Could not find a declaration file for module 'redux-persist/es/storage'. '/Users/rbu0374/Development/octodent/octodent.git/client/node_modules/redux-persist/es/storage/index.js' implicitly has an 'any' type.
  Try `npm install @types/redux-persist/es/storage` if it exists or add a new declaration (.d.ts) file containing `declare module 'redux-persist/es/storage';`

ERROR in [at-loader] ./src/main.tsx:16:31 
    TS2307: Cannot find module './locales/de-ch.json'.
20 09 2017 15:16:40.808:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
20 09 2017 15:16:40.810:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency
20 09 2017 15:16:40.878:INFO [launcher]: Starting browser ChromeHeadless
20 09 2017 15:16:41.232:INFO [HeadlessChrome 0.0.0 ()]: Connected on socket 61TQigS-rNwcBsx1AAAA with id 15095982
HeadlessChrome 0.0.0 (): Executed 0 of 0 ERROR (0.002 secs / 0 secs)
error Command failed with exit code 1.
有人知道为什么我的打字文件被忽略了吗?当我将我的应用程序与webpack捆绑在一起时,效果很好


提前谢谢你

我们的堆栈与您的堆栈有相同的问题:

  • 奥雷利亚
  • 打字稿
  • 网页包
  • 业力
我们的src文件夹中还有一个typings.d.ts,因此我们可以加载json文件

在我们的webpack.config.js中为awesome typescript loader启用transpileOnly选项对我们来说很有用

{ test: /\.ts$/i, loader: 'awesome-typescript-loader', exclude: nodeModulesDir, options: { transpileOnly: true } },

对您来说可能有点晚,但可能会帮助其他人。

遇到同样的问题,您找到解决方案了吗?