1. The original project uses dva,. When integrating typescript, refer to the official example given by dva
.
global.d.ts
require
typescript:
the following is the code involved in the error:
// tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"target": "es6",
"jsx": "react",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": false,
"noImplicitAny": false,
"noImplicitReturns": false,
"removeComments": true,
"strictNullChecks": false,
"outDir": "build",
"allowJs": true,
"allowSyntheticDefaultImports": true,
"lib": [
"es6",
"es7",
"dom"
],
"baseUrl": "./src",
"paths": {
"IconFont": [
"src/components/Iconfont"
]
}
},
"exclude": [
"dist",
"build",
"node_modules"
]
}
// global.d.ts
declare var require: {
<T>(path: string): T;
(paths: string[], callback: (...modules: any[]) => void): void;
ensure: (paths: string[], callback: (require: <T>(path: string) => T) => void) => void;
};
// package.json
"devDependencies": {
"awesome-typescript-loader": "^4.0.0",
"tslint": "^5.10.0",
"typescript": "^2.8.3",
},
"dependencies": {
"@types/react": "^16.3.14",
"@types/react-dom": "^16.0.5",
"dva": "^2.1.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
}
// ./node_modules/@types/node/index.d.ts
declare var require: NodeRequire;
interface NodeModule {
exports: any;
require: NodeRequireFunction;
id: string;
filename: string;
loaded: boolean;
parent: NodeModule | null;
children: NodeModule[];
paths: string[];
}
Please take a look at it. Thank you. Thank you.