加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – 使用React Native的Babel插件(babel-plugin-module-a

发布时间:2020-12-15 20:10:51 所属栏目:百科 来源:网络整理
导读:我想在我的React Native项目中使用 babel-plugin-module-alias将模块路径从../../../../components/foo转换为app / components / foo. 我试图在两个地方独立修改babel配置,但都不起作用. 一,在index.ios.js旁边的项目的根目录: { "plugins": [ ["babel-plug
我想在我的React Native项目中使用 babel-plugin-module-alias将模块路径从../../../../components/foo转换为app / components / foo.

我试图在两个地方独立修改babel配置,但都不起作用.

一,在index.ios.js旁边的项目的根目录:

{
  "plugins": [
    ["babel-plugin-module-alias",[
      { "src": "./app","expose": "app" }
    ]]
  ]
}

两个,在/node_modules/react-native/packager/react-packager/.babelrc:

{
  "retainLines": true,"compact": true,"comments": false,"plugins": [
    ["babel-plugin-module-alias","expose": "app" }
    ]],"syntax-async-functions","syntax-class-properties","syntax-trailing-function-commas","transform-class-properties","transform-es2015-arrow-functions","transform-es2015-block-scoping","transform-es2015-classes","transform-es2015-computed-properties","transform-es2015-constants","transform-es2015-destructuring",["transform-es2015-modules-commonjs",{"strict": false,"allowTopLevelThis": true}],"transform-es2015-parameters","transform-es2015-shorthand-properties","transform-es2015-spread","transform-es2015-template-literals","transform-flow-strip-types","transform-object-assign","transform-object-rest-spread","transform-react-display-name","transform-react-jsx","transform-regenerator","transform-es2015-for-of"
  ],"sourceMaps": false
}

它不会抛出任何错误,只是试图要求一个模块从’app / components / MyComponent’导入MyComponent;产生错误:

无法解决模块app / components / MyComponent ….无效的目录/ Users / node_modules / app / components / MyComponent.

我已经尝试了我知道的每个缓存:

watchman watch-del-all
rm -rf $TMPDIR/react-*
./node_modules/react-native/packager/packager.sh start --resetCache

任何进一步的想法将不胜感激!

解决方法

升级npm / node / react-native /对其最新的响应后:

react-native: ^0.29.0
react: 15.2.1
npm: 3.10.3
node: 6.3.0

然后:

watchman watch-del-all
npm start -- --reset-cache

这个问题消失了.

您可以在此处查看有关此问题的更多信息:https://github.com/facebook/react-native/issues/4968和https://github.com/tleunen/babel-plugin-module-alias/issues/29

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读