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.
What should I do?
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:
// @ts-ignore
to the line above the one with the errorexport const _ = '';
) so that the file is a module (from this ts issue)A little hacky, but might be all someone needs...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With