Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create-react-app --typescript: Cannot compile namespaces when the '--isolatedModules' flag is provided

I generated a project with npx create-react-app my-app-ts --typescript,
then I created two files, sw-build.js and sw.js under src/,

the code of sw-build.js and sw.js is from (Guidlines for Using Workbox).

There is an error:

Cannot compile namespaces when the '--isolatedModules' flag is provided.

enter image description here

What should I do?

like image 621
zwl1619 Avatar asked Dec 16 '18 15:12

zwl1619


1 Answers

Just for others that may end up here, a potential answer was posted on the github issue listed above: Guidlines for Using Workbox.

karannagupta commented

I've excluded the SW files in tsconfig.json like this:

{
 "compilerOptions": {
  ...
  },
  "include": [
    "src/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts",
    "src/sw-*.js",
    "src/idb.js"
  ]
}

Edit: Other options:

  • add // @ts-ignore to the line above the one with the error
  • add a nothing export (eg. export const _ = '';) so that the file is a module (from this ts issue)

A little hacky, but might be all someone needs...

like image 154
Jono Job Avatar answered Nov 16 '22 19:11

Jono Job