gpt4 book ai didi

reactjs - 模块解析失败 : Unexpected token. react-native/index.js "typeof"operator

转载 作者:行者123 更新时间:2023-12-03 15:10:44 24 4
gpt4 key购买 nike

我对前端很陌生——试图在 React 上实现客户端。添加“react-native”依赖并运行 webpack 后我收到以下错误:

ERROR in ./node_modules/react-native/index.js 13:7
Module parse failed: Unexpected token (13:7)
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
| 'use strict';
|
> import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo';
| import typeof ActivityIndicator from './Libraries/Components/ActivityIndicator/ActivityIndicator';
| import typeof Button from './Libraries/Components/Button';
@ ./node_modules/@react-navigation/native/lib/module/useBackButton.js 2:0-43 5:25-36
@ ./node_modules/@react-navigation/native/lib/module/index.js
@ ./src/main/js/app.js

我在 package.json 中有以下依赖项:
 "dependencies": {
"@react-native-community/masked-view": "^0.1.7",
"@react-navigation/native": "^5.1.4",
"@react-navigation/stack": "^5.2.9",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-native": "^0.62.1",
"react-native-gesture-handler": "^1.6.1",
"react-native-reanimated": "^1.7.1",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.4.0",
"rest": "^2.0.0"
},
"scripts": {
"watch": "webpack --watch -d"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@babel/preset-react": "^7.9.4",
"babel-loader": "^8.1.0",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11"
}

我假设“typeof”运算符无法识别,但为什么呢?

最佳答案

你尝试在浏览器中运行 React Native 吗?如果是,我建议使用 React Native for Web .
react-native无法在浏览器中运行。您需要从 react-native 添加一个别名至react-native-webwebpack.config.js ,所以改用这个包。

关注 React Native for Web documentation您需要对您的 webpack 配置进行此修改:

// webpack.config.js
module.exports = {
// ...the rest of your config

resolve: {
alias: {
'react-native$': 'react-native-web'
}
}
}

关于reactjs - 模块解析失败 : Unexpected token. react-native/index.js "typeof"operator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61035800/

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