2

The following StackOverflow answer told me how to use react-app-rewired to import JavaScript files from outside the src folder, without ejecting the app:

https://stackoverflow.com/a/55298684/377011

However, when using this with a Typescript file outside of the src folder (i.e. import * from '../../myfile.ts'), I get the following error:

Module not found: Can't resolve 'ts-loader' in '...\myapp'

So I installed ts-loader (yarn add ts-loader), but now I'm getting

Error: TypeScript emitted no output for ...\myapp\src\index.tsx

noEmit is set to true in my tsconfig.json.

Any idea?

Edit: This is my tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": [
    "src"
  ]
}

Jonas Sourlier
  • 13,684
  • 16
  • 77
  • 148
  • 1
    please show your tsconfig. I think you should add this file to the compilation process by adding it to the `include` or `files` property – nickbullock Jan 15 '20 at 14:24
  • @nickbullock See edit for tsconfig. The strange thing is that the file in the error message is a file from inside the project, i.e. inside the `src` folder. It's not an outside file. – Jonas Sourlier Jan 15 '20 at 14:34
  • try following steps: remove `noEmit: true` and change "include" to `"include": ["src/**/*"]` – nickbullock Jan 16 '20 at 08:39
  • @nickbullock Apparently, `create-react-app` instantly puts the `noEmit: true` back whenever it is removed. – Jonas Sourlier Jan 16 '20 at 17:27

0 Answers0