react-native-reanimated: Reanimated is not working in web
ERROR in ./node_modules/react-native-reanimated/src/Transitioning.js 36:6 Module parse failed: Unexpected token (36:6) 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
Using package.json
{
"name": "dev",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-native-reanimated": "^2.0.0",
"react-native-web": "^0.15.0"
},
"devDependencies": {
"@babel/core": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"@babel/preset-react": "^7.12.13",
"babel-loader": "^8.2.2",
"babel-plugin-react-native-web": "^0.15.0",
"html-webpack-plugin": "^5.3.1",
"prettier": "^2.2.1",
"webpack": "^5.25.0",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2"
},
"scripts": {
"start": "webpack serve --config webpack.config.js",
"build": "webpack --config webpack.config.js",
"format": "prettier --write ."
}
}
with webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
module.exports = {
mode: 'development',
entry: './index.js',
output: {
path: path.resolve(__dirname, './release'),
filename: 'bundle.js',
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: './index.html',
}),
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: ['babel-plugin-react-native-web'],
},
},
},
],
},
devServer: {
contentBase: path.join(__dirname, 'release'),
compress: true,
port: 3000,
},
resolve: {
alias: {
'react-native$': 'react-native-web',
},
},
};
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 25 (4 by maintainers)
I figured out a setup as well. I added a
config.module.rules
that wouldinclude
react-native-reanimated
.just added babel plugin to babel.config.js and it worked plugins: [ ‘@babel/plugin-proposal-export-namespace-from’, ‘react-native-reanimated/plugin’,
@kyleshevlin i managed to figure out my setup. here is my
webpack.config.js
. hope it helps.For posterity, if you’re using Expo and want Reanimated to work for web, there are instructions here: https://docs.expo.dev/versions/latest/sdk/reanimated/
npx expo install react-native-reanimated
babel.config.js
Hey @learncodingforweb The reason this issue was webpack configuration, I fixed this with this PR Example webpack config
Error can be seen on https://github.com/learncodingforweb/web_reanimated
@learncodingforweb, @gurkerl83 Change
exclude
key to:This happens because we use JSX syntax and your babel configuration doesn’t compile node_modules.