Tôi nhận được lỗi sau:nguyên cảo không thể tìm thấy Redux
node_modules/@types/react-redux/index.d.ts(8,24): error TS2307: Cannot find module 'redux'.
mặc dù đã cài đặt cả hai react-redux
và redux
(package.json
):
"dependencies": {
"react": "15.4.2",
"react-native": "0.42.3",
"react-redux": "^5.0.3",
"redux": "^3.6.0"
},
"devDependencies": {
"@types/react": "^15.0.18",
"@types/react-native": "^0.42.9",
"@types/react-redux": "^4.4.38",
"@types/redux": "^3.6.0",
"babel-jest": "19.0.0",
"babel-preset-react-native": "1.9.1",
"jest": "19.0.2",
"react-test-renderer": "15.4.2",
"tslint": "^4.5.1",
"typescript": "^2.2.1"
},
File README.md
trong @types/redux
nói:
This is a stub types definition for Redux (https://github.com/reactjs/redux).
Redux provides its own type definitions, so you don't need @types/redux installed!
nhưng un cài đặt gói @types/redux
không có sự khác biệt.
Bất kỳ ý tưởng nào?
CẬP NHẬT
Tôi nghĩ rằng bằng cách thêm một index.d.ts
đến @types/redux
thư mục (chỉ chứa export * from ../../redux/index
), nó sẽ giải quyết vấn đề, nhưng không có niềm vui.
Đây là tôi tsconfig.json
:
{
"compilerOptions": {
"target": "es2015",
"module": "es2015",
"jsx": "react",
"outDir": "build",
"rootDir": "src",
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
"experimentalDecorators": true,
"preserveConstEnums": true,
"allowJs": true,
"sourceMap": true
},
"filesGlob": [
"src/**/*.ts",
"src/**/*.tsx"
],
"exclude": [
"__tests__",
"index.android.js",
"index.ios.js",
"build",
"node_modules"
],
"compileOnSave": false
}
và tôi chắc chắn xóa các thư mục @types/redux
từ node_modules
. Tôi (rõ ràng) đang chạy TypeScript 2.2.1.
UPDATE 2
Mã sử dụng redux
:
import { combineReducers } from "redux"
export default combineReducers({})
Lưu ý rằng việc thêm một dấu chấm phẩy sau "redux"
không giúp.
Có, nó sẽ hoạt động mà không có '@ types/redux'. Trên thực tế, tôi nghĩ rằng tôi đã có vấn đề, khi tôi đã cài đặt '@ types/redux' ... Bạn có thể cung cấp một đoạn mã mà bạn đang nhập vào redux không? –
Chỉ cần chắc chắn, đặt ở đây tsconfig.json của bạn là tốt. –
'import {createStore, Store, Reducer} từ 'redux'' điều này hoạt động tốt trong bản 2.3.0-dev.20170320 –