react-native-ui-kitten: Module parse failed: Unexpected token. You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.
🐛 Bug Report
Not able to build code
UI Kitten and Eva version
Package | Version |
---|---|
@eva-design/eva | ^2.0.0-alpha.1 |
@ui-kitten/components | ^5.0.0-alpha.1 |
Environment information
System:
OS: macOS 10.15.3
CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
Binaries:
Node: 13.9.0 - ~/.nvm/versions/node/v13.9.0/bin/node
Yarn: 1.22.4 - ~/.yvm/shim/yarn
npm: 6.14.4 - ~/.nvm/versions/node/v13.9.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 27, 28
Build Tools: 27.0.3, 28.0.3, 29.0.3
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.6010548
Xcode: 11.4/11E146 - /usr/bin/xcodebuild
npmPackages:
react: ~16.13.1 => 16.13.1
react-native: https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz => 0.61.4
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 30
- Comments: 48
Steps
Install expo webpack config dependency
npm i -D @expo/webpack-config
Create
webpack.config.js
in the root folder of the project and add the code snippet belowThis code snippet is for
webpack.config
I believe instead ofbabel.config
For now, I’ve used installed
@expo/webpack-config
packages which let us modify the webpack file, createdwebpack.config
at root level and added this code snippetI know this code snippet is not clean. Any suggestions regarding this approach are much appreciated. Thanks! 😃
Adding the following underneath the “web” key in app.json also resolves the issue:
"build": { "babel": { "include": [ "@ui-kitten/components" ] }
@harryy2510 Thanks, this solution works well.
For anyone encountering this issue, I’m just gonna lay out the entire process in steps:
expo install @expo/webpack-config
Feels like a duplicate of #991. You’re trying to use
ui-kitten
inreact-native-web
(orexpo-web
in this case), and you need to make Webpack transpilenode_modules
or you’ll face these kinds of errors.You’ll have to add something like this in
babel.config
file:@jasuno If I’m correct
npm i -D @expo/webpack-config
It would be great if someone know how to configure webpack on an app without Expo.
@eunhyoung0313 @JordiOrriols
Is anyone else running into this issue when using Typescript and Expo?
I managed to get this to work on a Create React Application by using the documentation from React Native Elements - Usage on the Web
Install UI Kitten components
yarn add @eva-design/eva @ui-kitten/components react-native-svg
Install packages to override webpack config
yarn add -D @babel/plugin-proposal-class-properties customize-cra react-app-rewired
config-overrides.js
Create a new file called
config-overrides.js
in the root of the project and add the following code inside:Update start script
Update the
start
script inpackage.json
to:"start": "react-app-rewired start"
See if it works
Update
App.tsx
to:Hi, I have the same error but with NUXT. I put @expo/webpack-config and created webpack.config. But not work yet.
The workaround seems to be working. Just make sure to restart your stack after making the changes.
I am fairly new to it all, so I don’t have any hope of figuring out how to solve the actual issue in a PR. I do, however, not mind doing some leg work to get to replicability.
Question regarding this quirk. I was running a basic tutorial from last year using Expo + UI Kitten (v4 at the time). The setup is fairly simple:
One might see that it works on Native app emulators, but not Web. I get that token error that is mentioned by others. I tried downgrading to version UIKitten v4.4.1 and Eva 1.4.0 and it worked without issues. So I understand why the tutorial worked. Something that changed in v5 possibly broke this expo-kitten relationship.
I also tried the same on their snack.expo.io site, it was complaining at first, but it is working without the needed webpack workaround in their Web view and Native apps. Now I wonder if this can be replicated by others on their machines?
If it is a problem for everyone, should we therefore ask Expo to fix it in the webpack config as they have direct access to it? Or is it in UI Kitten’s ballpark to fix?
@artyorsh i fix, thank you for support! Ps. I’m working with next js and rnw and kitten ui
Thanks @harryy2510 it works. For anyone to whom his solution is not working. Dont forget to replace the package name inside dangerouslyAddModulePathsToTranspile key.
change react-scripts version in package.json to “react-scripts”: “^4.0.3” . create-react-app is not pulling the correct version that’s why you are facing this issue.
@harryy2510 @lesmo This is a library build issue. We moved to ts3.8 without thinking about optional chaining transpiling. Here seems like a correct way to fix this, should be done on the ui kitten side.
Thanks for sharing workarounds 👍
UPD
There is a stackoverflow answer on this issue.
hey while importing query-string in react it showing an error: ./node_modules/query-string/base.js 424:161 Module parse failed: Unexpected token (424:161) File was processed with these loaders:
| query: parse(extract(url), options), | …(options && options.parseFragmentIdentifier && hash ? {
Thanks @harryy2510 ! Yoursuggestions works great.
Here’s how to configure webpack with expo.
first, run
npm install @expo/webpack-config
create a
webpack.config.js
file in the root of your apppaste this:
now you should be able to setup your
App.js
orApp.tsx
file with ui-kitten and eva.@adammcarth I think UI Kitten team will be better able to answer this question. No hard feelings though 😃
Thanks for the info @harryy2510. I genuinely had no idea the
?.
operator had made it to the JavaScript core 🤷♀️My follow up questions are still going to be quite similar though. Why isn’t UI Kitten transpiling down to ES5 JavaScript? What are the benefits of remaining at ES Next and requiring projects to use additional Babel plugins when (I assume) it could just be transpiled to ES5 for increased support and flexibility?
The reason I’m asking these questions is because I’m happy to help make those changes if it was just an initial oversight. They weren’t meant to come off as accusations; apologies to everyone if they did 👍
Thank you very much that actually helped out, I was changing the one in my node modules… yeah I know a silly mistake
@the-phoenix
Use the workaround by @harryy2510 as a temporary solution. This definitely will be fixed in alpha.2, but no ETAs to be honest