mobxjs / mobx-react

React bindings for MobX

Home Page:https://mobx.js.org/react-integration.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to resolve module `./assertEnvironment`

dclipca opened this issue · comments

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"

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

@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/

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?

@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.

@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=="
    },

@mweststrate let me look into it.

@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 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"
  }

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

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.

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

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

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.

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.

Closing until more info becomes available