Webpack + React + TypeScript: Module not found … in … node_modules/react/

前端 未结 2 1014
抹茶落季
抹茶落季 2020-12-11 00:10

I\'m trying to put together a very basic project with React, TypeScript and Webpack. When I compile I get the following errors from the react folder in n

2条回答
  •  有刺的猬
    2020-12-11 00:17

    Webpack is not resolving .js files. Add this to your webpack.config.js.

    resolve: {
        extensions: [".ts", ".tsx", ".js", ".jsx"]
    },
    

    Here is the tsconfig.json I used to run your example.

    {
      "compilerOptions": {
        "jsx": "react",
        "lib": ["es6", "dom"],
        "rootDir": "src",
        "module": "commonjs",
        "target": "es5",
        "sourceMap": true,
        "moduleResolution": "node",
        "noImplicitReturns": true,
        "noImplicitThis": true,
        "noImplicitAny": true,
        "strictNullChecks": true
      },
      "include": [
        "./src"
      ],
      "exclude": [
        "node_modules",
        "build"
      ]
    }
    

提交回复
热议问题