#reactjs #react-native #webpack #expo #babel-loader
#reactjs #react-родной #webpack #выставка #вавилонский загрузчик
Вопрос:
Я пытаюсь перенести весь код в своем приложении с es6 на es5, поскольку у меня возникли проблемы с Safari 9 и IE11.
Однако, когда я включаю node_modules в мой babel.config.js Я получаю следующую ошибку
SyntaxError: /Users/salmanmohamed/Documents/apps/rapioUserApp/App.js: Support for the experimental syntax 'jsx' isn't currently enabled (41:5):
39 | //return <Text>Hii</Text>;
40 | return loading ? (
> 41 | <LoadingLayout>
| ^
42 | <LoadingText>{copy.loading.texts.fonts}</LoadingText>
43 | <ActivityIndicator />
44 | </LoadingLayout>
Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing.
Я попытался добавить предустановку react, но я по-прежнему получаю ту же ошибку, что и при попытке добавить плагин-syntax-jsx
Я использую следующие стеки
Реагируйте на родной язык с помощью EXPO Реагируйте на родной язык для Интернета с помощью Expo
babel.config.js
module.exports = function (api) {
api.cache(true);
return {
//exclude: [/bcore-jsb/, /bwebpack/buildinb/,/bnode_modules/],
include: /(node_modules)/,
test: /.(tsx?)|(js)$|(jsx)$/,
presets: [
["@babel/react"],
["@babel/preset-typescript"],
[
"@babel/preset-env",
{
corejs: { version: 3 },
useBuiltIns: "usage",
targets: {
esmodules: true,
browsers: [
"last 5 versions",
"ie >= 9",
" safari >= 7",
"ios_saf >= 9",
],
},
loose: true,
},
],
[
"babel-preset-expo",
{
corejs: { version: 3 },
targets: {
esmodules: true,
browsers: [
"last 5 versions",
"ie >= 9",
"safari >= 7",
"ios_saf >= 9",
],
},
},
],
],
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-computed-properties",
[
"module-resolver",
{
alias: {
"@Components": "./components",
"@Containers": "./containers",
"@Hooks": "./hooks",
"@Controllers": "./controllers",
"@Assets": "./assets",
"@Helpers": "./helpers",
"@Actions": "./actions",
"@Services": "./services",
"@Utils": "./utils",
},
},
],
],
};
};
webpack.config.js
const createExpoWebpackConfigAsync = require("@expo/webpack-config");
const { getExpoBabelLoader } = require("@expo/webpack-config/utils");
const modulesToTranspile = [
"ansi-regex",
"ansi-styles",
"chalk",
"react-dev-utils",
];
module.exports = async function (env, argv) {
env.babel = { dangerouslyAddModulePathsToTranspile: modulesToTranspile };
const config = await createExpoWebpackConfigAsync(env, argv);
// Customize the config before returning it.
const loader = getExpoBabelLoader(config);
if (loader) {
// Modify the loader...
loader.include("@babel/polyfill");
loader.include("react-app-polyfill");
loader.include("react-app-polyfill/ie9");
loader.include("react-app-polyfill/ie11");
loader.include("core-js");
// console.warn(loader)
}
return config;
};
Ответ №1:
Включение плагинов в мой веб-пакет сработало для меня
const createExpoWebpackConfigAsync = require("@expo/webpack-config");
const { getExpoBabelLoader } = require("@expo/webpack-config/utils");
const modulesToTranspile = [
"ansi-regex",
"ansi-styles",
"chalk",
"react-dev-utils",
"@react-navigation",
"styled-components",
"node_modules",
];
module.exports = async function (env, argv) {
env.babel = { dangerouslyAddModulePathsToTranspile: modulesToTranspile };
const config = await createExpoWebpackConfigAsync(env, argv);
// Customize the config before returning it.
const loader = getExpoBabelLoader(config);
if (loader) {
loader.include("@babel/plugin-proposal-class-properties");
loader.include("@babel/plugin-transform-arrow-functions");
loader.include("@babel/plugin-transform-block-scoping");
loader.include("@babel/plugin-transform-sticky-regex");
loader.include("@babel/plugin-transform-unicode-regex");
loader.include("@babel/plugin-transform-dotall-regex");
loader.include("@babel/plugin-transform-named-capturing-groups-regex");
loader.include("@babel/plugin-transform-runtime");
// console.warn(loader)
}
return config;
};