Storybook: native storybook unable to resolve babel aliases

Created on 24 Nov 2017  路  7Comments  路  Source: storybookjs/storybook

I had a working storybook that broke when upgrading to RN 0.50. It can no longer resolve the babel aliases. The package was created with react-native init

RN: 0.50.3
Storybook: 3.2.16

My babelrc:

{
  "presets": ["flow", "react-native"],
  "plugins": [
    ["babel-plugin-module-resolver", {
      "root": ["."],
      "alias": {
        "crypto": "./src/polyfills/modules/crypto/index.js",
        "xenon": "./src"
      }
    }]
  ],
  "env": {
    "test": {
    },
  },
}
react-native babel / webpack inactive

Most helpful comment

Looks to be due to a breaking change in RN 0.50.
See https://github.com/facebook/react-native/commit/023ac57337b351959d443133c3c09607c4ffc800

Can be resolved by creating a rn-cli.config.js file with the following contents:

module.exports = {
  getEnableBabelRCLookup() {
    return true;
  },
};

(taken from https://github.com/facebook/react-native/releases/tag/v0.50.0)

I've not looked in to how storybook resolves references, is this approach just a workaround or the best way forward?

All 7 comments

Looks to be due to a breaking change in RN 0.50.
See https://github.com/facebook/react-native/commit/023ac57337b351959d443133c3c09607c4ffc800

Can be resolved by creating a rn-cli.config.js file with the following contents:

module.exports = {
  getEnableBabelRCLookup() {
    return true;
  },
};

(taken from https://github.com/facebook/react-native/releases/tag/v0.50.0)

I've not looked in to how storybook resolves references, is this approach just a workaround or the best way forward?

Switch to haul just for storybook. That works.

@ritz078 not for me. Haul runs in to issues with some of my dependencies. Specifically victory-native.

I guess I just need to configure webpack.haul.js correctly but this doesn't feel like the happy path.

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks!

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

I'm getting the same error

{
  "presets": ["module:metro-react-native-babel-preset"],
  "env": {
    "production": {
      "plugins": [
        "transform-react-constant-elements",
        "transform-remove-console"
      ]
    }
  },
  "plugins": [
    [
      "module-resolver",
      {
        "cwd": "babelrc",
        "root": ["./"],
        "alias": {
          "@assets": "./assets",
          "@domain": "./artifacts/domain",
          "@util": "./artifacts/util",
          "@lib": "./artifacts/lib",
          "@components": "./artifacts/components"
        }
      }
    ]
  ]
}

Already have the ff. file above - it still complains Module @components does not exist in the Haste module map

Already have the rn-cli.config.js file above, app works fine - just storybook.

any news regarding this one?
same thing here, app works fine but when running storybook babel's not able to resolve any alias while pointing the --projectRoot storybook instead of replacing the app entry point

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shilman picture shilman  路  3Comments

levithomason picture levithomason  路  3Comments

sakulstra picture sakulstra  路  3Comments

tlrobinson picture tlrobinson  路  3Comments

purplecones picture purplecones  路  3Comments