A problem in introducing ts Migration into js Project

react-js project, now introduces typescript, installs typescript @ types/react @ types/node , and configures tsconfig.json

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "allowJs": true,
    "target": "es2015",
    "module": "commonjs",
    "allowSyntheticDefaultImports": true,
    "baseUrl": "src",
    // "alwaysStrict": true,
    "jsx": "react",
    "traceResolution": true,
    "paths": {
      "$component/*": [
        "component/*"
      ],
      "$config/*": [
        "config/*"
      ],
      "$utils/*": [
        "utils/*"
      ],
      "$utils": [
        "utils/index.js"
      ],
    },
    "typeRoots": [
      "node",
      "node_modules/@types",
      "./typings"
    ]
  },
  "exclude": [
    "node_modules",
    "dist",
    "**/*.test.ts",
    "public"
  ]

}

npm start will report some problems, but it will not affect the running of the project

======== Resolving type reference directive "webpack", containing file "/Users/mypc/Desktop/webpack-demo/node_modules/dll-link-webpack-plugin/dist/index.d.ts", root directory "/Users/mypc/Desktop/webpack-demo/node,/Users/mypc/Desktop/webpack-demo/node_modules/@types,/Users/mypc/Desktop/webpack-demo/typings". ========
Resolving with primary search path "/Users/mypc/Desktop/webpack-demo/node, /Users/mypc/Desktop/webpack-demo/node_modules/@types, /Users/mypc/Desktop/webpack-demo/typings".
Directory "/Users/mypc/Desktop/webpack-demo/node" does not exist, skipping all lookups in it.
Looking up in "node_modules" folder, initial location "/Users/mypc/Desktop/webpack-demo/node_modules/dll-link-webpack-plugin/dist".
Directory "/Users/mypc/Desktop/webpack-demo/node_modules/dll-link-webpack-plugin/dist/node_modules" does not exist, skippingall lookups in it.
File "/Users/mypc/Desktop/webpack-demo/node_modules/dll-link-webpack-plugin/node_modules/webpack.d.ts" does not exist.
Directory "/Users/mypc/Desktop/webpack-demo/node_modules/dll-link-webpack-plugin/node_modules/@types" does not exist, skipping all lookups in it.
"package.json" does not have a "typings" field.
"package.json" does not have a "types" field.
"package.json" has "main" field "lib/webpack.js" that references "/Users/mypc/Desktop/webpack-demo/node_modules/webpack/lib/webpack.js".
"package.json" does not have a "typesVersions" field.
Found "package.json" at "/Users/mypc/Desktop/webpack-demo/node_modules/webpack/package.json". Package ID is "webpack/lib/webpack.d.ts@4.17.1".
File "/Users/mypc/Desktop/webpack-demo/node_modules/webpack.d.ts" does not exist.
"package.json" does not have a "typings" field.
"package.json" does not have a "types" field.
File "/Users/mypc/Desktop/webpack-demo/node_modules/webpack/index.d.ts" does not exist.
File "/Users/mypc/Desktop/webpack-demo/node_modules/@types/webpack.d.ts" does not exist.
Directory "/Users/mypc/Desktop/node_modules" does not exist, skipping all lookups in it.
File "/Users/mypc/node_modules/webpack.d.ts" does not exist.
Directory "/Users/mypc/node_modules/@types" does not exist, skipping all lookups in it.
Directory "/Users/node_modules" does not exist, skipping all lookups in it.
Directory "/node_modules" does not exist, skipping all lookups in it.
======== Type reference directive "webpack" was not resolved. ========
======== Resolving type reference directive "webpack", containing file "/Users/mypc/Desktop/webpack-demo/node_modules/dll-link-webpack-plugin/dist/CacheController.d.ts", root directory "/Users/mypc/Desktop/webpack-demo/node,/Users/mypc/Desktop/webpack-demo/node_modules/@types,/Users/mypc/Desktop/webpack-demo/typings". ========
Resolving with primary search path "/Users/mypc/Desktop/webpack-demo/node, /Users/mypc/Desktop/webpack-demo/node_modules/@types, /Users/mypc/Desktop/webpack-demo/typings".
Directory "/Users/mypc/Desktop/webpack-demo/node" does not exist, skipping all lookups in it.
Looking up in "node_modules" folder, initial location "/Users/mypc/Desktop/webpack-demo/node_modules/dll-link-webpack-plugin/dist".
Directory "/Users/mypc/Desktop/webpack-demo/node_modules/dll-link-webpack-plugin/dist/node_modules" does not exist, skippingall lookups in it.
File "/Users/mypc/Desktop/webpack-demo/node_modules/dll-link-webpack-plugin/node_modules/webpack.d.ts" does not exist.
Directory "/Users/mypc/Desktop/webpack-demo/node_modules/dll-link-webpack-plugin/node_modules/@types" does not exist, skipping all lookups in it.
"package.json" does not have a "typings" field.
"package.json" does not have a "types" field.
"package.json" has "main" field "lib/webpack.js" that references "/Users/mypc/Desktop/webpack-demo/node_modules/webpack/lib/webpack.js".
"package.json" does not have a "typesVersions" field.
Found "package.json" at "/Users/mypc/Desktop/webpack-demo/node_modules/webpack/package.json". Package ID is "webpack/lib/webpack.d.ts@4.17.1".
File "/Users/mypc/Desktop/webpack-demo/node_modules/webpack.d.ts" does not exist.
"package.json" does not have a "typings" field.
"package.json" does not have a "types" field.
File "/Users/mypc/Desktop/webpack-demo/node_modules/webpack/index.d.ts" does not exist.
File "/Users/mypc/Desktop/webpack-demo/node_modules/@types/webpack.d.ts" does not exist.
Directory "/Users/mypc/Desktop/node_modules" does not exist, skipping all lookups in it.
File "/Users/mypc/node_modules/webpack.d.ts" does not exist.
Directory "/Users/mypc/node_modules/@types" does not exist, skipping all lookups in it.
Directory "/Users/node_modules" does not exist, skipping all lookups in it.

"package.json" does not have a" typings" field.

how are these problems caused and how to fix them? Thank you


https://github.com/mozilla/so...


because you use webpack but ts cannot find the type definition file of webpack , that is, * .d.ts . You can add a constraint to the ts compilation directory in the configuration file, such as removing the files or directories referencing webpack in exclude , exclude: ["webpack"]

Menu