I have a problem building Vue3 and Vue2 apps in monorepo.
When trying to build the apps I see an error in Vue3 app:
error in ./src/App.vue
Syntax Error: TypeError: Cannot read properties of undefined (reading 'styles')
ERROR in ./src/App.vue
Module build failed (from ../../node_modules/#vue/cli-service/node_modules/vue-loader/dist/index.js):
TypeError: Cannot read properties of undefined (reading 'styles')
at Object.loader (../../node_modules/#vue/cli-service/node_modules/vue-loader/dist/index.js:70:34)
# ./src/main.ts 2:0-28 5:10-13
Monorepo tool: TurboRepo
Package manager: yarn v1
Vue3 version: 3.2.13
Vue2 version: 2.6.11
Vue3 cli version: 5.0.8
Vue2 cli version: 4.5.17
webpack for vue3: 5.54
webpack for vue2: 4.46
Folder structure
├─ apps/
│ ├─ vue3-app/
│ │ ├─ package.json
│ ├─ vue2-app-1/
│ │ ├─ package.json
│ ├─ vue2-app-2/
│ │ ├─ package.json
├─ package.json
In the root package.json I declared workspaces
"workspaces": {
"packages": [
"apps/vue2-app-1",
"apps/vue2-app-2",
"apps/vue3-app"
],
I think it could be a problem with packages in root node_modules (Vue3 trying to use wrong package version?) so I tried yarn nohoist option but it didn't change anything
"nohoist": [
"vue3-app/**/vue",
"vue3-app/**/vue/**",
"vue2-app-1/**/vue/**",
"vue2-app-1/**/vue/**",
"vue2-app-2/**/vue/**",
"vue2-app-2/**/vue/**",
"vue3-app/**/vue-loader",
"vue3-app/**/vue-loader/**",
"vue2-app-1/**/vue-loader/**",
"vue2-app-1/**/vue-loader/**",
"vue2-app-2/**/vue-loader/**",
"vue2-app-2/**/vue-loader/**"
]
What could be causing the problem?
I am stuck at this for a long time now. Have tried everything. Can someone please help me understand why is this happening? I have attached the screenshot of the error as below
[PS C:\Users\Hp\Desktop\projects> expo init Mealtogo
Migrate to using:
› npx create-expo-app --template
√ Choose a template: » blank a minimal app as clean as an empty canvas
Error downloading and extracting template package: Error: Could not parse JSON returned from "npm pack expo-template-blank --dry-run".
expo-template-blank-46.0.21.tgz
Error: Unexpected token e in JSON at position 0
× Something went wrong while downloading and extracting the template.
Can't read JSON file: C:\Users\Hp\Desktop\projects\Mealtogo\app.json
└─ Cause: Error: ENOENT: no such file or directory, open 'C:\Users\Hp\Desktop\projects\Mealtogo\app.json'
├─ readAsync C:\Users\Hp\AppData\Roaming\npm\node_modules\expo-cli\node_modules#expo\json-file\src\JsonFile.ts:158:13
├─ extractAndPrepareTemplateAppAsync C:\Users\Hp\AppData\Roaming\npm\node_modules\expo-cli\src\commands\utils\extractTemplateAppAsync.ts:25:25
└─ actionAsync C:\Users\Hp\AppData\Roaming\npm\node_modules\expo-cli\src\commands\initAsync.ts:290:19]1
try with:
npx create-expo-app --template
I started getting this error today
Invariant Violation: "main" has not been registered. This can happen
if:
Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
A module failed to load due to an error and AppRegistry.registerComponent wasn't called.
I read in this thread Invariant Violation: "main" has not been registered While running react-native app that might be because i have multiple versions of react native safe area content.
I ran npm why react-native-safe-area-content and this is what i got
react-native-safe-area-context#4.2.4
node_modules/react-native-safe-area-context
react-native-safe-area-context#"4.2.4" from the root project peer
react-native-safe-area-context#">= 3.0.0" from
#react-navigation/elements#1.3.3
node_modules/#react-navigation/elements
#react-navigation/elements#"^1.3.3" from #react-navigation/native-stack#6.6.2
node_modules/#react-navigation/native-stack
#react-navigation/native-stack#"^6.6.2" from the root project
#react-navigation/elements#"^1.3.3" from #react-navigation/stack#6.2.1
node_modules/#react-navigation/stack
#react-navigation/stack#"^6.2.1" from the root project peer react-native-safe-area-context#">= 3.0.0" from
#react-navigation/native-stack#6.6.2
node_modules/#react-navigation/native-stack
#react-navigation/native-stack#"^6.6.2" from the root project peer react-native-safe-area-context#">= 3.0.0" from
#react-navigation/stack#6.2.1 node_modules/#react-navigation/stack
#react-navigation/stack#"^6.2.1" from the root project
But i don't know what to do now, how should i proceed?
In my case, the version of the react-native-safe-area-context in my package.json was different from the one used in a dependency. The solution was to use the same version the dependency was using.
My package.json had 4.3.1 while my dependency (react-native-gifted-chat) had 4.4.1, a higher version.
To figure out the versions I used yarn why react-native-safe-area-context.
$ yarn why react-native-safe-area-context
yarn why v1.22.19
[1/4] 🤔 Why do we have the module "react-native-safe-area-context"...?
[2/4] 🚚 Initialising dependency graph...
[3/4] 🔍 Finding dependency...
[4/4] 🚡 Calculating file sizes...
=> Found "react-native-safe-area-context#4.3.1"
info Reasons this module exists
- "_project_#expo-app" depends on it
- Hoisted from "_project_#expo-app#react-native-safe-area-context"
info Disk size without dependencies: "1016KB"
info Disk size with unique dependencies: "1016KB"
info Disk size with transitive dependencies: "1016KB"
info Number of shared dependencies: 0
=> Found "react-native-gifted-chat#react-native-safe-area-context#4.4.1"
info This module exists because "_project_#expo-app#react-native-gifted-chat" depends on it.
info Disk size without dependencies: "968KB"
info Disk size with unique dependencies: "968KB"
info Disk size with transitive dependencies: "968KB"
info Number of shared dependencies: 0
✨ Done in 0.94s.
To match the versions I installed the specific version using the command below
yarn add react-native-safe-area-context#4.4.1
When trying to run my React Native app I get this error:
error: bundling failed: Error: Expected path `/Users/jgallaso/Projects/aerogear/aerogear-react-native-core/index.js` to be relative to one of the project roots
at toLocalPath (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/node-haste/lib/toLocalPath.js:33:9)
at ModuleCache.getModule (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/node-haste/ModuleCache.js:94:20)
at ModuleResolver._getFileResolvedModule (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:320:42)
at ModuleResolver.resolveDependency (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:311:989)
at ResolutionRequest.resolveDependency (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:96:16)
at DependencyGraph.resolveDependency (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/node-haste/DependencyGraph.js:269:4352)
at /Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:201:36
at next (native)
at step (/Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:256:306)
at /Users/jgallaso/Projects/aerogear/aerogear-js-sdk/example/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:256:536
BUNDLE [android, dev] ./index.js ▓▓▓▓▓▓▓▓▓░░░░░░░ 56.6% (331/440), failed.
My app has a dependency installed aerogear-react-native-core that is a Native Module. Source code is at: https://github.com/josemigallas/aerogear-react-native-core
This package on the other hand depends on other TS one (I ignore if this is problematic) and this code is located at: https://github.com/josemigallas/aerogear-js-sdk/tree/poc_react_native_library/packages/core
And the app code that actually tries to use all this is located at: https://github.com/josemigallas/aerogear-js-sdk/tree/poc_react_native_library/example/react-native
This means:
App
└─┬ aerogear-react-native-core#0.0.2
└── #aerogearmobile/core#1.0.0
Since this is all at development stage, nothing is pushed to npmjs, I'm just using npm link to include all dependencies.
Honestly I don't have a clue why this is failing, without the second dependency everything worked all right so that makes me think typescript has something to do. However, the error is complaining about aerogear-react-native-sdk's index.js file so maybe the error is related with the link.
I tried deleting all caches, re-installing npm modules, re-running the bundler many times...
If you have used "npm link" in the project, that might be the reason. Metro Bundler does not work with symlink correctly. Try to install the dependency without using "npm link".
How can I get the tree of a module available to npm, but not installed locally ?
npm ll does the job for locally installed packages. But it doesn't work for modules not installed or modules installed globally.
I tried npm list bower but that's not it.
You can generate NPM dependency trees without the need of installing
a dependency by using the command
npm list
This will generate a dependency tree for the project at the current directory and print it to the console.
You can get the dependency tree of a specific dependency like so:
npm list [dependency]
You can also set the maximum depth level by doing
npm list --depth=[depth]
Note that you can only view the dependency tree of a dependency that you have installed either globally, or locally to the NPM project.
You can use the npm-remote-ls module. You can install it globally:
npm install -g npm-remote-ls
And then call:
npm-remote-ls bower
Alternatively, npm#5.2.0 installed then you can use npx and avoid globally installing the command - just call:
npx npm-remote-ls bower
This site allows you to view a packages tree as a node graph in 2D or 3D.
http://npm.anvaka.com/#/view/2d/waterline
Great work from #Avanka!
Here is the unpowerful official command:
npm view <PACKAGE> dependencies
It prints only the direct dependencies, not the whole tree.
You can use howfat which also displays dependency statistics:
npx howfat jasmine
If you want to get the actually dependency path of specific package and want to know why you have it, you can simply ask yarn why <MODULE>.
example:
$> yarn why mime-db
yarn why v1.5.1
[1/4] Why do we have the module "mime-db"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "mime-db#1.37.0"
info Reasons this module exists
- "coveralls#request#mime-types" depends on it
- Hoisted from "coveralls#request#mime-types#mime-db"
info Disk size without dependencies: "196kB"
info Disk size with unique dependencies: "196kB"
info Disk size with transitive dependencies: "196kB"
info Number of shared dependencies: 0
Done in 0.65s.
View All the metadata about npm module
npm view mongoose(module name)
View All Dependencies of module
npm view mongoose dependencies
View All Version or Versions module
npm view mongoose version
npm view mongoose versions
View All the keywords
npm view mongoose keywords
This command output all modules with dependencies in a tree structure:
npm ls -a
If you are using yarn, then you can go with yarn list from the root directory of the project. It'll give you a tree like structure of all the transitive dependencies like below:
├─ #ampproject/toolbox-core#2.7.4
│ ├─ cross-fetch#3.0.6
│ └─ lru-cache#6.0.0
├─ #ampproject/toolbox-optimizer#2.7.0-alpha.1
│ ├─ #ampproject/toolbox-core#^2.6.0
│ ├─ #ampproject/toolbox-runtime-version#^2.7.0-alpha.1
│ ├─ #ampproject/toolbox-script-csp#^2.5.4
│ ├─ #ampproject/toolbox-validator-rules#^2.5.4
│ ├─ abort-controller#3.0.0
│ ├─ cross-fetch#3.0.5
│ ├─ cross-fetch#3.0.5
│ │ └─ node-fetch#2.6.0
│ ├─ cssnano-preset-simple#1.2.0
│ │ ├─ caniuse-lite#^1.0.30001093
│ │ ├─ postcss#^7.0.32
│ │ └─ postcss#7.0.35
│ │ ├─ chalk#^2.4.2
│ │ ├─ source-map#^0.6.1
│ │ └─ supports-color#^6.1.0
To get it as a list:
% npx npm-remote-ls --flatten dugite -d false -o false
[
'dugite#1.91.3',
'checksum#0.1.1',
'progress#2.0.3',
'mkdirp#0.5.5',
'rimraf#2.7.1',
'tar#4.4.13',
'optimist#0.3.7',
'got#9.6.0',
'minimist#1.2.5',
'chownr#1.1.4',
'glob#7.1.6',
'fs-minipass#1.2.7',
'minizlib#1.3.3',
'minipass#2.9.0',
'safe-buffer#5.2.1',
'yallist#3.1.1',
'wordwrap#0.0.3',
'#szmarczak/http-timer#1.1.2',
'cacheable-request#6.1.0',
'#sindresorhus/is#0.14.0',
'decompress-response#3.3.0',
'duplexer3#0.1.4',
'lowercase-keys#1.0.1',
'mimic-response#1.0.1',
'get-stream#4.1.0',
'to-readable-stream#1.0.0',
'p-cancelable#1.1.0',
'url-parse-lax#3.0.0',
'fs.realpath#1.0.0',
'inflight#1.0.6',
'inherits#2.0.4',
'once#1.4.0',
'path-is-absolute#1.0.1',
'minimatch#3.0.4',
'defer-to-connect#1.1.3',
'clone-response#1.0.2',
'get-stream#5.2.0',
'http-cache-semantics#4.1.0',
'lowercase-keys#2.0.0',
'responselike#1.0.2',
'keyv#3.1.0',
'pump#3.0.0',
'prepend-http#2.0.0',
'normalize-url#4.5.0',
'wrappy#1.0.2',
'brace-expansion#1.1.11',
'json-buffer#3.0.0',
'end-of-stream#1.4.4',
'concat-map#0.0.1',
'balanced-match#1.0.0'
]
There is also a nice web app to see the dependencies in a weighted map kind of view.
For example:
https://bundlephobia.com/result?p=sanitize-html#1.19.1
Unfortunately npm still doesn't have a way to view dependencies of non-installed packages. Not even a package's page list the dependencies correctly. 🙄
Luckily installing yarn:
brew install yarn
Allows one to use its info command to view accurate dependencies:
yarn info #angular/router#4.4.7 dependencies
yarn info #angular/router#4.4.7 peerDependencies