mobxjs / mobx-react

React bindings for MobX
https://mobx.js.org/react-integration.html
MIT License
4.85k stars 349 forks source link

Unable to resolve module `./assertEnvironment` #899

Closed dclipca closed 4 years ago

dclipca commented 4 years ago

After upgrading from "mobx": "^5.15.7" and "mobx-react": "^6.3.0" to "mobx": "^6.0.0" and "mobx-react": "^7.0.0" I receive an Unable to resolve module `./assertEnvironment error.

Intended outcome

The app doesn't have any errors

Actual outcome

error: Error: Unable to resolve module `./assertEnvironment` from `node_modules/mobx-react-lite/es/index.js`: 

None of these files exist:
  * node_modules/mobx-react-lite/es/assertEnvironment(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
  * node_modules/mobx-react-lite/es/assertEnvironment/index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
    at ModuleResolver.resolveDependency (/Users/virtumonde/Desktop/dev/project/project-client/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:163:15)
    at ResolutionRequest.resolveDependency (/Users/virtumonde/Desktop/dev/project/project-client/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (/Users/virtumonde/Desktop/dev/project/project-client/node_modules/metro/src/node-haste/DependencyGraph.js:287:16)
    at Object.resolve (/Users/virtumonde/Desktop/dev/project/project-client/node_modules/metro/src/lib/transformHelpers.js:267:42)
    at /Users/virtumonde/Desktop/dev/project/project-client/node_modules/metro/src/DeltaBundler/traverseDependencies.js:434:31
    at Array.map (<anonymous>)
    at resolveDependencies (/Users/virtumonde/Desktop/dev/project/project-client/node_modules/metro/src/DeltaBundler/traverseDependencies.js:431:18)
    at /Users/virtumonde/Desktop/dev/project/project-client/node_modules/metro/src/DeltaBundler/traverseDependencies.js:275:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/virtumonde/Desktop/dev/project/project-client/node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24)

How to reproduce the issue

Install "mobx": "^6.0.0" and "mobx-react": "^7.0.0" on "react-native": "0.63.3"

Versions

"mobx": "^6.0.0",
"mobx-react": "^7.0.0"
"react-native": "0.63.3"
mweststrate commented 4 years ago

could you verify in your lockfile / node_modules which version of mobx-react-lite is installed? should be 3.0.0 at least

danielkcz commented 4 years ago

@mweststrate Isn't the path wrong here?

node_modules/mobx-react-lite/es/assertEnvironment

Should be in utils dir ... https://unpkg.com/browse/mobx-react-lite@3.0.0/es/utils/

danielkcz commented 4 years ago

What I mean is the assertEnvironment is used by mobx-react-lite internally only. How is it possible something else is importing it from a different path?

mweststrate commented 4 years ago

@virtumonde yeah that sounds like you have somehow a hardcoded import into the mobx-react-library somewhere? VSCode tends to do that sometimes :-P. I suspect this issue is further unrelated to the actual package. That file has moved indeed recently, but is internal so should not affect anything.

dclipca commented 4 years ago

@mweststrate

    "mobx-react": {
      "version": "7.0.0",
      "resolved": "https://registry.npmjs.org/mobx-react/-/mobx-react-7.0.0.tgz",
      "integrity": "sha512-yxbTG+ovn/GbgF3+QdQahkL5sXiITtwvkoXM6PNqd0V4jvO53cnr/YM4PYuA+0Ig95IW1nojA3qViJx9ufJm6w==",
      "requires": {
        "mobx-react-lite": "^3.0.0"
      }
    },
    "mobx-react-lite": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/mobx-react-lite/-/mobx-react-lite-3.0.0.tgz",
      "integrity": "sha512-SJgrTD9mfClFOsamB+0y6zjteSMr4gkp9usnpIeEi8E+lW3lMgDa3hnD4PJgLGoENpJ8/9OmO3vrkA50SNy0mw=="
    },
dclipca commented 4 years ago

@mweststrate let me look into it.

dclipca commented 4 years ago

@mweststrate by hardcoded import you mean I am myself trying to access node_modules/mobx-react-lite/es/index.js? I've scanned my project for this kind of imports and didn't find anything. Let's wait to see if other people encounter this error.

mweststrate commented 4 years ago

yes

On Thu, Oct 1, 2020 at 2:44 PM Dan Clipca notifications@github.com wrote:

@mweststrate https://github.com/mweststrate by hardcoded import you mean I am myself trying to access node_modules/mobx-react-lite/es/index.js ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mobxjs/mobx-react/issues/899#issuecomment-702145603, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4NBABVZOMB5LV35LVQCTSISBVDANCNFSM4SALP44A .

mweststrate commented 4 years ago

having something in the form of import from "mobx-react-lite/something"

On Thu, Oct 1, 2020 at 2:46 PM Michel Weststrate mweststrate@gmail.com wrote:

yes

On Thu, Oct 1, 2020 at 2:44 PM Dan Clipca notifications@github.com wrote:

@mweststrate https://github.com/mweststrate by hardcoded import you mean I am myself trying to access node_modules/mobx-react-lite/es/index.js?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mobxjs/mobx-react/issues/899#issuecomment-702145603, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4NBABVZOMB5LV35LVQCTSISBVDANCNFSM4SALP44A .

dclipca commented 4 years ago

@mweststrate the only mention of mobx-react-lite is in my package-lock.json. I am sure that my code does not import it. Maybe other packages might import it? Here are my dependencies:

  "dependencies": {
    "@react-native-community/async-storage": "^1.12.0",
    "@react-native-firebase/app": "^8.4.5",
    "@react-native-firebase/crashlytics": "^8.4.8",
    "@react-native-mapbox-gl/maps": "^8.1.0-rc.4",
    "google-protobuf": "^3.13.0",
    "grpc-web": "^1.2.1",
    "lottie-react-native": "^3.5.0",
    "mobx": "^6.0.0",
    "mobx-react": "^7.0.0",
    "react": "16.13.1",
    "react-native": "0.63.3",
    "react-native-action-button": "^2.8.5",
    "react-native-modal": "^11.5.6",
    "react-native-permissions": "^2.2.2",
    "react-native-popup-menu": "^0.15.9",
    "react-native-safe-area-context": "^3.1.8",
    "react-native-sound": "^0.11.0",
    "react-native-toast-message": "^1.3.3",
    "react-native-vector-icons": "^7.1.0"
  },
  "devDependencies": {
    "@babel/core": "^7.11.6",
    "@babel/plugin-proposal-class-properties": "^7.10.4",
    "@babel/plugin-proposal-decorators": "^7.10.5",
    "@babel/runtime": "^7.11.2",
    "@react-native-community/eslint-config": "^2.0.0",
    "@types/geojson": "^7946.0.7",
    "@types/jest": "^26.0.14",
    "@types/react-native": "^0.63.23",
    "@types/react-test-renderer": "^16.9.3",
    "@types/uuid-parse": "^1.0.0",
    "@typescript-eslint/eslint-plugin": "^4.3.0",
    "@typescript-eslint/parser": "^4.3.0",
    "@types/google-protobuf": "^3.7.3",
    "@types/react-native-vector-icons": "^6.4.6",
    "babel-jest": "^26.3.0",
    "eslint": "^7.10.0",
    "jest": "^26.4.2",
    "metro-react-native-babel-preset": "^0.63.0",
    "prettier": "^2.1.2",
    "react-test-renderer": "16.13.1",
    "typescript": "^4.0.3"
  }
dclipca commented 4 years ago

Also, switching back to "mobx-react": "^6.3.0" and "mobx": "^6.0.0" doesn't trigger the error.

danielkcz commented 4 years ago

Something is apparently importing the old file. Maybe even some sort of cache? Might be even duplicate versions of packages. I recommend deleting node_modules and reinstalling from the scratch.

dclipca commented 4 years ago

@FredyC I already did that 5 times. I will look into other possibilities soon as for now this is not critical to me.

mweststrate commented 4 years ago

If switching to mobx-react:6.3 and mobx:6 does work for you, there is definitely something wrong, as those should normally not be able to work together :-P. There is something weird, are you sure you have cleared all caches, have the same folder open in terminal, ide and project that is running, etc? Otherwise I recommend to build a minimal repro, usually the process of doing that finds the culprit

On Thu, Oct 1, 2020 at 2:55 PM Dan Clipca notifications@github.com wrote:

@FredyC https://github.com/FredyC I already did that 5 times. I will look into other possibilities soon as for now this is not critical to me.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mobxjs/mobx-react/issues/899#issuecomment-702152939, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4NBHRF44T2FSJ6B4RYUTSISC6LANCNFSM4SALP44A .

dclipca commented 4 years ago

@mweststrate I meant "mobx": "^5.15.7" instead of "mobx": "^6.0.0". My bad.

mweststrate commented 4 years ago

ok, nonetheless would be great to build a minimal reproduction. Might be an uncommon module format or something that messes things up.

mweststrate commented 4 years ago

Just for confirmation, I just tried both a fresh CRA and a fresh RN project with mobx@6 + mobx-react@7 and they work fine. So this really seems to be a local issue. You can try to run yarn why mobx-react-lite (or the other 2) to see if another package accidentally brings a different version of those packages.

mweststrate commented 4 years ago

Healthy output looks like:

yarn why mobx-react-lite
yarn why v1.22.4
[1/4] 🤔  Why do we have the module "mobx-react-lite"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "mobx-react-lite@3.0.0"
info Reasons this module exists
   - "mobx-react" depends on it
   - Hoisted from "mobx-react#mobx-react-lite"
info Disk size without dependencies: "316KB"
info Disk size with unique dependencies: "316KB"
info Disk size with transitive dependencies: "316KB"
info Number of shared dependencies: 0
✨  Done in 0.48s.
mweststrate commented 4 years ago

Closing until more info becomes available