babel-plugin-module-resolver icon indicating copy to clipboard operation
babel-plugin-module-resolver copied to clipboard

Doesn't work in Production

Open rishisingh-dev opened this issue 3 years ago • 19 comments

I am using this package in my ReactNative project. It works well in simulator but when I publish app to app store, it doesn't work. (To be more exact, only assets folder doesn't work. Other folders work.)

jsconfig.json

{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "allowSyntheticDefaultImports": true,
    "baseUrl": "./",
    "paths": {
      "assets/*": ["src/assets/*"],
      "components/*": ["src/components/*"],
      "navigators/*": ["src/navigators/*"],
      "screens/*": ["src/screens/*"],
      "core/*": ["src/core/*"],
      "questions/*": ["src/questions/*"],
      "redux/*": ["src/redux/*"]
    }
  }
}

environment

"babel-plugin-module-resolver": "^4.0.0",
"react": "16.13.1",
"react-native": "0.63.0",

npm - 4.2.0
node - 10.21.0

rishisingh-dev avatar Jul 21 '20 10:07 rishisingh-dev

Similar issues here - I get a bundle error when attempting distribution: error Unable to resolve module components/root from index.js: components/root could not be found within the project.

Possibly related: https://github.com/facebook/react-native/issues/29351 https://stackoverflow.com/questions/62806319/main-jsbundle-does-not-exist-this-must-be-a-bug-with-main-jsbundle-issue-afte/62914788#62914788

afestein avatar Jul 22 '20 09:07 afestein

This answer in the same stackoverflow thread worked for me: https://stackoverflow.com/a/62872851/1873778

babel.config.js -> .babelrc.js

cogell avatar Jul 30 '20 19:07 cogell

Have same issue in Production.... Guys, could you please check, we are really blocked. It happens in [email protected], [email protected] works fine. Looks like they have changed some mechanism for babel

oleksandr-dziuban avatar Aug 06 '20 12:08 oleksandr-dziuban

For me, the solution was a combination of the following suggestions:

https://stackoverflow.com/a/62914788 https://github.com/facebook/react-native/issues/29351#issuecomment-657929014

afestein avatar Aug 06 '20 21:08 afestein

@afestein It doesn't work for me... Did you try production builds for iOS successfully?

oleksandr-dziuban avatar Aug 12 '20 14:08 oleksandr-dziuban

@tleunen Could you please help with this issue? It is related to [email protected]+ versions.... and this is really big blocker for all production projects with this babel plugin.. Thanks a lot

oleksandr-dziuban avatar Aug 12 '20 14:08 oleksandr-dziuban

@oleksandr-dziuban I've never used this plugin with React Native so I unfortunately cannot help. So hopefully some other users and RN devs can help with this issue, and if there's something to be fixed, feel free to send a PR.

tleunen avatar Aug 12 '20 14:08 tleunen

have the same issue

Yuriy1988 avatar Aug 12 '20 14:08 Yuriy1988

@oleksandr-dziuban I've never used this plugin with React Native so I unfortunately cannot help. So hopefully some other users and RN devs can help with this issue, and if there's something to be fixed, feel free to send a PR.

Issue not in this library, but in react-native code.. Possibly this PR will solve the issue: https://github.com/facebook/react-native/pull/29477

oleksandr-dziuban avatar Aug 12 '20 14:08 oleksandr-dziuban

faced the same issue after updating RN to 0.63.0 :(

Fedir-S avatar Aug 12 '20 14:08 Fedir-S

Additionally raised this issue for react native repo: https://github.com/facebook/react-native/issues/29636

It is critical issue for projects with this babel plugin

oleksandr-dziuban avatar Aug 13 '20 10:08 oleksandr-dziuban

Yes, I can confirm, this PR fixes the issue! facebook/react-native#29477

I have assembled release iOS build locally with this change and it works!

oleksandr-dziuban avatar Aug 13 '20 10:08 oleksandr-dziuban

~Maybe this is an unrelated issue, but it appears that this plugin will pick the first key that starts with the alias. eg~

// babel.config.js
{
  "plugins": [
    [
      "module-resolver",
      {
        "root": ["."],
        "alias": {
          "a/b": "./src/a/b/index",
          "a/b/c": "./src/a/b/c/index"
        }
      }
    ]
  ]
}

// src/app.js
import x from "a/b/c"; // resolves to "./a/b/index/c"

sparebytes avatar Aug 28 '20 21:08 sparebytes

Maybe this is an unrelated issue, but it appears that this plugin will pick the first key that starts with the alias. eg

// babel.config.js
{
  "plugins": [
    [
      "module-resolver",
      {
        "root": ["."],
        "alias": {
          "a/b": "./src/a/b/index",
          "a/b/c": "./src/a/b/c/index"
        }
      }
    ]
  ]
}

// src/app.js
import x from "a/b/c"; // resolves to "./a/b/index/c"

No, it doesn't work. I use alias and release builds failed for iOS. The reason in react-native 0.63.2 change for react-native-xcode.sh file.

oleksandr-dziuban avatar Aug 31 '20 11:08 oleksandr-dziuban

Thank you very much for pointing to the PR that fixes the bug @oleksandr-dziuban

I used https://www.npmjs.com/package/patch-package to patch react-native with the PR changes after installing packages. It worked for me.

abumalick avatar Sep 01 '20 13:09 abumalick

Thank you very much for pointing to the PR that fixes the bug @oleksandr-dziuban

I used https://www.npmjs.com/package/patch-package to patch react-native with the PR changes after installing packages. It worked for me.

Hi, yes, I'm using this workaround too, but we need this PR to be merged anyway as it is critical iOS issue on react-native platform

oleksandr-dziuban avatar Sep 07 '20 14:09 oleksandr-dziuban

I'm still seeing this issue in a 0.66 react native build. It all works correctly in dev on android and ios, as well as a production android build. But when I try to bundle for iOS in production it can't resolve any of the aliases.

Is anyone else still seeing this? I've scoured and tested everyone's previous solutions outlined through the many linked issues in this thread to no avail

tbakerx avatar Nov 03 '21 19:11 tbakerx

I'm still seeing this issue in a 0.66 react native build. It all works correctly in dev on android and ios, as well as a production android build. But when I try to bundle for iOS in production it can't resolve any of the aliases.

Is anyone else still seeing this? I've scoured and tested everyone's previous solutions outlined through the many linked issues in this thread to no avail

I also have the problem, do you resolve it?

314new avatar Nov 14 '21 13:11 314new

https://github.com/tleunen/babel-plugin-module-resolver/issues/332#issuecomment-439346463

@tbakerx @314new Have you tried this config? It works for me.

raykle avatar Nov 19 '21 01:11 raykle