简体   繁体   English

TS2304:在Webpack / Angular 2中找不到名称“描述”

[英]TS2304: Cannot find name 'describe' in Webpack / Angular 2

I've searched this issue extensively and nothing I found has fixed it. 我已经广泛搜索了此问题,但发现没有任何问题可以解决。 I'm trying to use webpack to run a single jasmine test. 我正在尝试使用webpack运行单个茉莉花测试。 I attempted to follow the tutorial on the Angular website but it's...not really correct or complete. 我试图按照Angular网站上的教程进行操作,但这并不是真的正确或完整。

Here's what I've tried so far: 到目前为止,这是我尝试过的方法:

  • Installed Jasmine types, they are present in my node_modules/@types/jasmine 已安装的Jasmine类型,它们存在于我的node_modules / @ types / jasmine中
  • Added "types": ["jasmine"] to my tsconfig.json even though you don't have to do that in Typescript 2.0.X 在您的tsconfig.json中添加了"types": ["jasmine"] ,即使您不必在Typescript 2.0.X中执行此操作
  • Added "typeRoots": ["./node_modules/@types"] to my tsconfig.json even though you don't have to do that in Typescript 2.0.X 在我的tsconfig.json中添加了"typeRoots": ["./node_modules/@types"] ,即使您不必在Typescript 2.0.X中执行此操作
  • Added import {} from 'jasmine'; import {} from 'jasmine';添加了import {} from 'jasmine'; to my unit tests as described here: Angular 2 Unit Tests: Cannot find name 'describe' 我的单元测试,如下所述: Angular 2单元测试:找不到名称“描述”

At that point it felt like I was way off base, something else has to be going on here. 那时,感觉好像我离基地很远,这里还必须进行其他操作。 I'm using awesome-typescript-loader, maybe it can't figure out types? 我正在使用awesome-typescript-loader,也许无法弄清楚类型?

I'm using the 2.0.9 version of typescript, and my config files are as follows: 我正在使用2.0.9版本的打字稿,我的配置文件如下:

webpack.test.ts webpack.test.ts

var webpack = require('webpack');
var helpers = require('./helpers');

module.exports = {
  devtool: 'inline-source-map',

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

  module: {
    rules: [
      {
        test: /\.ts$/,
        loaders: [
          {
            loader: 'awesome-typescript-loader',
            options: { configFileName: helpers.root('tsconfig.json') }
          } , 'angular2-template-loader'
        ]
      },
      {
        test: /\.html$/,
        loader: 'html-loader'

      },
      {
        test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
        loader: 'null-loader'
      },
      {
        test: /\.css$/,
        exclude: helpers.root('src', 'app'),
        loader: 'null-loader'
      },
      {
        test: /\.css$/,
        include: helpers.root('src', 'app'),
        loader: 'raw-loader'
      }
    ]
  },

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

tsconfig.json tsconfig.json

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2015",
      "dom"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5"
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

EDIT: Command I'm using to run the test: karma start ./config/karma.conf.js --single-run 编辑:我用来运行测试的karma start ./config/karma.conf.js --single-runkarma start ./config/karma.conf.js --single-run

Ugh...I found it. gh ...我找到了。 As I said in my post I'm using typescript 2.0.9, but the latest version of @types/jasmine uses keyof , which is a features of typescript 2.1... :/ 正如我在帖子中所说的那样,我正在使用打字稿2.0.9,但最新版本的@ types / jasmine使用keyof ,这是打字稿2.1的功能...:/

I reverted @types/jasmine to 2.5.41 and everything is fine. 我将@ types / jasmine恢复为2.5.41,一切都很好。

I installed an older version of jasmine with this command: 我使用以下命令安装了较旧版本的茉莉花:

npm install --save-dev @types/jasmine@2.5.41

and the problem solved. 问题就解决了

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

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