GoogleChrome / GoogleChrome/workbox

Error running generateSW - "Please pass in a valid CommonJS module that exports your configuration"

Open
#3,413 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
13k
Forks
880
Avg merge
2h 44m
Merged PRs (30d)
8

Description

Following the instructions here - https://developer.chrome.com/docs/workbox/modules/workbox-cli -

$ npx workbox-cli wizard
...
To build your service worker, run
workbox generateSW workbox-config.js
as part of a build process.

$ npx workbox-cli generateSW workbox-config.js
**Please pass in a valid CommonJS module that exports your configuration.**
module is not defined

My project's package.json has
```json
{
"type": "module",
}
```

It looks like `read-config` uses node's require fn -

https://github.com/GoogleChrome/workbox/blob/e26d8d7507f9412ba029922f3d9920e68710f2cf/packages/workbox-cli/src/lib/read-config.ts#L16

I renamed workbox-config.js to workbox-config.cjs - then it works okay -

$ npx workbox-cli generateSW workbox-config.js
Using configuration from workbox-config.cjs.
The service worker files were written to:
• .../public/sw.js
• .../public/sw.js.map
• .../public/workbox-5911a5e4.js
• .../public/workbox-5911a5e4.js.map
The service worker will precache 62 URLs, totaling 179 kB.

So should the wizard default to writing a .cjs file instead of .js?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.