简体   繁体   中英

Error TS2305: Module @types/angular has no exported member 'cookies'

I am having an issue with cookies not being defined in angular scope.

npm run start builds and starts the app just fine, but when trying to run npm test that executes jest command, I am getting this error:

`Test suite failed to run app/components/Component1/Component1.ts:1:10

  • error TS2305: Module '"../../../../../node_modules/@types/angular"' has no exported member 'cookies'.`

in Component1.ts there is this import: import { cookies } from 'angular';

Build and run - ok. Testing - not ok.

If you know where the issue can be hidden, please help:) Thank you.

my package.json:

 { "dependencies": {..., "angular": "^1.8.0", "angular-cookies": "1.8.0", "babel-polyfill": "^6.2.0", ... }, "devDependencies": { "@types/angular": "^1.8.0", "@types/angular-cookies": "^1.8.0", "@types/jest": "^26.0.19", "angular-mock": "^1.0.0", "angular-mocks": "^1.8.2", "angularjs-jest": "^0.1.4", "babel-core": "^6.24.1", "babel-loader": "^7.0.0", "jest": "^26.6.3", "ts-jest": "^26.4.4", ... } }

solution for my issue was adding angular-cookies to tsconfig.test.json file. I still do not understand why angular-cookies since source code and production build is taking types and definitions from angular package (and through IDE I can link to angular module rather than angular-cookies). But that's life is all about - mysteries.

 { "extends": "./tsconfig.json", "compilerOptions": { "types": [ "node", "jest", "angular-cookies" --> THIS VERY LINE SOLVED MY ISSUE ] }, "include": [ "index.d.ts", "**/*.test.ts" ] }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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