If you attempt to use a Javascript file ending in ".cjs" in an expo webpack build, then it will fail to include that file in the source file compilation. Instead, it treats those files as "assets".
Please specify your device/emulator/simulator platform, model and version
web, chrome browser
Error output
No response
Reproducible demo or steps to reproduce from a blank project
Try to use any package that uses .cjs files in a newly generated expo project, after running npm run web and viewing the page on a browser you can see errors related to the file usage.
The specific package I was testing with was 'axios', simply trying to create a client:
import axios from 'axios'
// this will error claiming that axios does not exist
axios.create()
Summary
If you attempt to use a Javascript file ending in ".cjs" in an expo webpack build, then it will fail to include that file in the source file compilation. Instead, it treats those files as "assets".
The same problem seems to exist in "create react app", so I guess maybe Expo is using the same webpack config under the hood: https://github.com/facebook/create-react-app/pull/12021
Currently you can work around the issue by overriding the expo webpack config using a similar workaround to what is described here: https://github.com/facebook/create-react-app/pull/12021#issuecomment-1108426483
Environment
Please specify your device/emulator/simulator platform, model and version
web, chrome browser
Error output
No response
Reproducible demo or steps to reproduce from a blank project
Try to use any package that uses
.cjs
files in a newly generated expo project, after runningnpm run web
and viewing the page on a browser you can see errors related to the file usage.The specific package I was testing with was 'axios', simply trying to create a client: