gpt4 book ai didi

reactjs - Babel - .js 文件中具有 JSX 语法的节点模块会破坏编译

转载 作者:行者123 更新时间:2023-12-03 13:53:32 26 4
gpt4 key购买 nike

导入 .JS 文件中使用 JSX 语法的模块时,我收到 SyntaxError。

其中一个例子是“react-navigation”

Failed to compile.

./node_modules/@react-navigation/native/dist/ResourceSavingSceneView.js
SyntaxError: /Users/my_user/Projects/my-react-native-web-app/node_modules/@react-navigation/native/dist/ResourceSavingSceneView.js: Unexpected token(35:11)

33 | } = this.props;
34 |
> 35 | return <View style={styles.container} collapsable={false} removeClippedSubviews={Platform.OS === 'android' ? removeClippedSubviews: !isFocused && removeClippedSubviews}>
| ^
36 | <View style={this._mustAlwaysBeVisible() || isFocused ?styles.innerAttached : styles.innerDetached}>
37 | {awake ? <SceneView {...rest} navigation={childNavigation} /> : null}
38 | </View>

下面是我的 babel 配置:

module.exports = function(api) {
api.cache(true);
return {
plugins: [
[
"@babel/plugin-proposal-class-properties",
{
loose: true
}
],
[
"module-resolver",
{
alias: {
"^react-native$": "react-native-web"
}
}
]
],
presets: [["react-app"], ["babel-preset-expo"]]
};
};

希望有人知道发生了什么

谢谢:)

最佳答案

你必须明确告诉 webpack 转译 react-navigation

      // Process JS with Babel.
{
test: /\.(js|jsx|mjs)$/,
include: [
`${paths.appNodeModules}/react-navigation`,

引用文献:webpack.config.dev.js#L141

关于reactjs - Babel - .js 文件中具有 JSX 语法的节点模块会破坏编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53744415/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com