Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expo Webpack treats ".cjs" files as assets and not source files #18

Open
ajwootto opened this issue Jul 24, 2023 · 2 comments
Open

Expo Webpack treats ".cjs" files as assets and not source files #18

ajwootto opened this issue Jul 24, 2023 · 2 comments

Comments

@ajwootto
Copy link

ajwootto commented Jul 24, 2023

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:
facebook/create-react-app#12021

Currently you can work around the issue by overriding the expo webpack config using a similar workaround to what is described here:
facebook/create-react-app#12021 (comment)

Environment

  expo-env-info 1.0.5 environment info:
    System:
      OS: macOS 12.6.6
      Shell: 5.8.1 - /bin/zsh
    Binaries:
      Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
      Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.0/bin/yarn
      npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
      Watchman: 2023.03.13.00 - /opt/homebrew/bin/watchman
    Managers:
      CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
    IDEs:
      Android Studio: 2021.3 AI-213.7172.25.2113.9123335
      Xcode: 14.2/14C18 - /usr/bin/xcodebuild
    npmPackages:
      @expo/webpack-config: ^18.0.1 => 18.1.2
      expo: ~48.0.18 => 48.0.20
      react: 18.2.0 => 18.2.0
      react-dom: 18.2.0 => 18.2.0
      react-native: 0.71.8 => 0.71.8
      react-native-web: ~0.18.10 => 0.18.12
    Expo Workflow: managed

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()
@geforcefan
Copy link

+1

@byCedric byCedric transferred this issue from expo/expo-cli Dec 30, 2023
@ChenXiaoTemp
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants