gpt4 book ai didi

javascript - 在React Native中使用装饰器,找不到变量: require

转载 作者:行者123 更新时间:2023-12-03 07:16:28 25 4
gpt4 key购买 nike

我正在尝试在我的 RN 项目中使用装饰器:

以下是我的 package.json 文件:

{
"name": "testApp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"autobind-decorator": "^1.3.3",
"babel-core": "^6.7.4",
"babel-loader": "^6.2.4",
"babel-plugin-transform-class-properties": "^6.6.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-runtime": "^6.6.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-react-native": "^1.5.6",
"babel-preset-stage-0": "^6.5.0",
"babel-runtime": "^6.6.1",
"react": "^0.14.8",
"react-native": "^0.22.2",
"webpack": "^1.12.14"
}
}

这是我的 .babelrc:

{
"plugins": [
"transform-runtime",
"transform-decorators-legacy",
"transform-class-properties"
],
"presets": ["es2015", "react", "stage-0", "react-native"]
}

我收到错误消息 ReferenceError: Can't find variable: require
。我尝试了很多帖子但无法得到任何解决方案。我使用 react-native init testApp

创建了新的 RN 项目

最佳答案

修复了由于预设顺序而导致的错误:我删除了所有其他预设并将预设更改为“react-native”,现在一切正常。

关于javascript - 在React Native中使用装饰器,找不到变量: require,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36403582/

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