我对前端很陌生-尝试在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”运算符,但是为什么呢?
我只花了几个小时来处理这个确切的问题。
首先,您可以尝试添加"@babel/preset-flow"
到.babelrc
文件中(安装后)。在这里建议这样做,但实际上对我没有用。
对我有用的只是添加externals: { "react-native": true },
到我的webpack.config.js
文件中。我的配置文件最终看起来像这样:
const path = require("path")
module.exports = {
entry: "./src/index.js",
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist"),
},
externals: {
"react-native": true,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ["babel-loader"],
},
// ...
],
},
}
我的理解是这react-native
是一个依赖项,因此@babel/preset-flow
实际上并没有被触发来帮助解释flow
这些文件中的格式-它只能处理文件主要"entry"
位置中的webpack.config.js
文件。
希望这可以帮助某个人。如果我有点偏离基准,请随时对此答案发表评论,我将对其进行更新:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句