[英]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: 到目前为止,这是我尝试过的方法:
"types": ["jasmine"]
to my tsconfig.json even though you don't have to do that in Typescript 2.0.X "types": ["jasmine"]
,即使您不必在Typescript 2.0.X中执行此操作 "typeRoots": ["./node_modules/@types"]
to my tsconfig.json even though you don't have to do that in Typescript 2.0.X "typeRoots": ["./node_modules/@types"]
,即使您不必在Typescript 2.0.X中执行此操作 import {} from 'jasmine';
import {} from 'jasmine';
添加了import {} from 'jasmine';
to my unit tests as described here: Angular 2 Unit Tests: Cannot find name 'describe' 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-run
: karma 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.