react-cosmos: Webpack error with brand new Expo project
What’s wrong?
Based on the docs I was given the impression Cosmos can be used across React Native and web in an Expo project but using Cosmos in an Expo project yields webpack errors.
Steps to reproduce
- Clone
https://github.com/tomparkp/react-cosmos-expo-bug yarn installandyarn cosmos- See webpack error.
ERROR in ./test.fixture.js 4:15
Module parse failed: Unexpected token (4:15)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import React from "react";
|
> export default <Text>Hello World</Text>;
|
@ ./node_modules/react-cosmos/dist/plugins/webpack/client/userDeps.js 7:22-76
@ ./node_modules/react-cosmos/dist/plugins/webpack/client/index.js
@ multi ./node_modules/react-cosmos/dist/plugins/webpack/client/reactDevtoolsHook.js ./node_modules/@skidding/webpack-hot-middleware/client.js?reload=true&overlay=false ./node_modules/react-cosmos/dist/plugins/webpack/client/index.js
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (6 by maintainers)
ok, it was my mistake twice:
I’d also like to use Cosmos in a web + iOS Expo project, although it makes sense that it would be a lot for one person to maintain all these different configurations.
In case it helps someone else out, I did the following to get mirroring working on Expo SDK 44 :
expo customize:webto generate awebpack.config.js. (If this is exiting without making a config file, make sure you read the instructions - I was tripped up by the UI here.)envpassed tocreateExpoWebpackConfigAsyncdoesn’t accept a string anymore - it expects an object of this shape; and (2) the HtmlWebpackPlugin requires aprojectRootin its options (not sure what is different about running via Cosmos that omits this).Putting that all together, I modified the
webpack.config.jsto look like this:As stated above, this will probably break when Expo updates. I’m using a managed Expo project; here are the relevant(?) dependency versions that I’m working with:
I have only used this briefly in iOS/web development so far; I haven’t tried exporting.