unable to add package in yarn workspace monorepo - yarnpkg

I am trying to import components in a shared package in a monorepo, but am unable to do so.
I have the following package.json files under the root of a repo that I want to run as a monorepo. /apps/billing is a create-react-app. /apps/shared is going to contain components for billing and other apps.
/package.json
{
"name": "root",
"version": "1.0.0",
"private": true,
"description": "",
"main": "index.js",
"workspaces": [
"apps/*"
],
"scripts": {
"billing": "cd apps/billing; yarn start"
},
"author": "",
"license": "ISC",
"dependencies": {}
}
/apps/billing/package.json
{
"name": "#root/billing",
"version": "0.1.0",
"private": true,
"dependencies": {
<snip>
},
}
/apps/billing/shared.json
{
"name": "#root/shared",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}
In the /apps/billing directory I tried to run yarn add #root/shared and get the following output:
error An unexpected error occurred: "https://registry.yarnpkg.com/#root%2fshared: Not found".
In billing, when I try to import a component from shared
import Button from '#root/shared/components/Button';
I get
Module not found: Can't resolve '#root/shared/components/Button'
Are there additional steps to setup a yarn monorepo?

It's wrong structure for monorepo.
Also you've wrongly named /apps/billing/shared.json it should be package.json instead of shared.json
At first your package.json in the root folder should be named eg. #name-of-your-app/monorepo
then packages under your root.
fe. in apps/billing
{
"name": "#name-of-your-app/billing-app",
"version": "0.1.0",
"private": true,
"dependencies": {
// any dependencies
},
then your shared components:
each should be in its own directory
each should have its own package.json
Let's say that you have shared/Button
then Button should be in its own directory and contain package.json
eg. of shared/Button/package.json/
{
"name": "#name-of-your-app/button",
"version": "0.1.0",
"private": true,
"dependencies": {
// any dependencies
},
and if you want to use this button in your billing-app
then you should at first add this as dependency IMPORTANT watchout for version of your button in package.json, the same should be installed as dependency in your app, otherwise it will finish up with bunch of errors.
-Then when you want to import this button in any component under your billing-app then import should look like this:
import Button from '#name-of-your-app/button'
You can read more about workspaces here:
yarn workspaces
Also I recommend to read more about monorepo structure fe. here

Related

Yarn does not see workspaces

I have the following configuration in a root workspace. The strange thing is that for backend it works, but for frontend - doesn't, no matter how I rename this
{
"private": true,
"name": "root",
"workspaces": [
"packages/frontend",
"packages/backend"
],
"scripts": {
"client": "yarn workspace frontend start",
"client-test": "yarn workspace frontend test",
"server": "yarn workspace backend start",
"start": "conc --kill-others-on-fail \"yarn client\" \"yarn server\""
},
"devDependencies": {
"concurrently": "^7.6.0"
}
}
And it always says: $ yarn workspace frontend test
error Unknown workspace "frontend".
info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I tried to start from all directories, nothing works
The thing is that it does not matter how folders are called inside of "packages", the important thing is that package.json of each workspace should be called correspondingly:
{
"name": "frontend",
"version": "1.0.0",
"private": true,
...
}

Electron-Forge SQLite3 database not accessible on MacOS Darwin build after unzipping

I'm having some issues with a CRUD desktop application I developed with the help of a freelancer. It's an electron-forge build that works seamlessly on Windows 10, and works on MacOS initially when accessing the out folder, the strange thing happens when:
I use npm run publish to zip the Mac/Darwin instance
I manually package.zip the results of npm run make
When I do this, and unzip the file to run, the SQLite integration fails completely. The app appears to be working upon start, but no changes can be made to the DB objects, nor can new objects be made.
The freelancer who put together the DB integration said he was not able to solve this issue, but it's impossible to put apps in marketplaces without zipping the application for delivery. I can post code if necessary, I just don't even know what aspect of the code would be relevant, and feel like there has to be something I can install/put in my package.json that might solve this, but I'm just not sure.
Here is my package.json file in case that is helpful:
{
"name": "C",
"productName": "C",
"version": "1.0.2",
"description": "My Electron application description",
"main": "src/index.js",
"scripts": {
"start": "cross-env NODE_ENV=development electron-forge start",
"package": "electron-forge package",
"make": "cross-env NODE_ENV=production electron-forge make",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\""
},
"keywords": [],
"author": {
"name": "A",
"email": "xxx#gmail.com"
},
"license": "NA",
"config": {
"forge": {
"packagerConfig": {
"icon": "src/images/n.ico"
},
"makers": [
{
"name": "#electron-forge/maker-squirrel",
"config": {
"name": "C"
}
},
{
"name": "#electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "#electron-forge/maker-deb",
"config": {}
},
{
"name": "#electron-forge/maker-rpm",
"config": {}
}
]
}
},
"dependencies": {
"axios": "^0.21.1",
"bootstrap": "^4.6.0",
"cross-env": "^7.0.3",
"ebay-oauth-nodejs-client": "^1.2.1",
"electron-better-ipc": "^1.1.1",
"electron-squirrel-startup": "^1.0.0",
"electron-store": "^7.0.2",
"jquery": "^3.6.0",
"json-csv": "^3.0.6",
"sequelize": "^6.5.0",
"sqlite3": "^5.0.0"
},
"devDependencies": {
"#electron-forge/cli": "^6.0.0-beta.54",
"#electron-forge/maker-deb": "^6.0.0-beta.54",
"#electron-forge/maker-rpm": "^6.0.0-beta.54",
"#electron-forge/maker-squirrel": "^6.0.0-beta.54",
"#electron-forge/maker-zip": "^6.0.0-beta.54",
"electron": "10.1.5"
}
}
I found that by simply creating a DMG target (see https://www.electronforge.io/config/makers/dmg) that I did not need to worry about unzipping process. I believe DMG is the ideal approach for packaging Mac OS apps that have something like a SQLite database integration within.

procfile no changing from web to worker

I'm trying to Host my bot "chompbot" in Heroku.
But when i change Procfile from web to worker, does not change anything.
I've tried
Here is my package.json
"name": "chompbot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": "^11.5.1",
"mysql": "^2.17.1"
}
}
And here is my Procfile
worker: index.js
When i commit and push, anything happens on "Web", and do not appears "Worker" option
( Ps.: The MySql database is fully working on cloud, so, can't be the dependencies )
Can someone help me to change from Web to Worker?
http://prntscr.com/pb21qs
Your worker should be the script that starts you server, index.js is only the file name. What you want to do is to use your npm start script instead of index.js

Yarn workspaces with Lerna still adding packages to subfolders

I'm confused about Yarn Workspaces. I've followed this tutorial: https://medium.com/trabe/monorepo-setup-with-lerna-and-yarn-workspaces-5d747d7c0e91 but in one of the sub projects I still get packages added to node_modules which are duplicated from the root node_modules. Full test repo is here: https://github.com/donker/Dnn.React.Test
Root package.json:
{
"name": "dnn-react-test",
"version": "1.0.0",
"description": "DNN React Component Library",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/dnnsoftware/Dnn.React.Common.git"
},
"scripts": {
},
"private": true,
"workspaces": [
"packages/*"
],
"devDependencies": {
"lerna": "2.11.0"
}
}
Subproject package.json:
{
"name": "dnn-tooltip",
"version": "0.2.5",
"description": "Display an icon and associated tooltip showing a message from an array parameter",
"main": "index.js",
"scripts": {
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/dnnsoftware/Dnn.React.Common"
},
"dependencies": {
"lodash": "4.17.10",
"react-portal-tooltip": "2.4.0",
"dnn-global-styles": "^0.0.5"
}
}
Result: packages/Tooltip/node_modules/lodash created.
Expected: Tooltip uses node_modules/lodash from the root folder.
Getting lerna and yarn to properly work together requires adding the following two key value pairs to your lerna.json:
"npmClient": "yarn",
"useWorkspaces": true
Although this does not directly relate to your question, I would also suggest changing
"workspaces": [
"packages/*"
],
to
"workspaces": [
"packages/**"
],
to make lerna pick up packages in subfolders (like /packages/components/button).

Unable to register my bower package - No versions available

My bower package sass-smacss:
https://github.com/leongaban/sass-smacss
And my bower.json file:
{
"name": "sass-smacss",
"version": "1.0.0",
"description": "SMACSS based SASS modules for organized style writing",
"homepage": "https://github.com/leongaban/sass-smacss",
"main": "sass/main_web.scss",
"authors": [
{
"name": "Leon Gaban",
"email": "leongaban#gmail.com",
"homepage": "http://leongaban.com",
"twitter": "#leongaban"
}
],
"repository": {
"type": "git",
"url": "https://github.com/leongaban/sass-smacss.git"
},
"keywords": [
"sass",
"css",
"smacss",
"stylesheets"
],
"license": "MIT",
"ignore": [
"**/.*",
"bower.json",
"bower_components"
]
}
Looks like I was able to bower register it, however when I run bower info sass-smacss I get No versions available, and it's not found on Bower's packages search.
Followed instructions from:
http://bower.io/docs/creating-packages/
http://bob.yexley.net/creating-and-maintaining-your-own-bower-package/
UPDATE
Thanks #drorb I added a git tag. However after registering it again, still getting the No versions available message :(
I did git tag -a v1.0.0 -m 'First version'
Bower package versions are based on Git tags. In your case the sass-smacss Git repository does not contain any tag (only a master branch).
Also notice that tag names (effectively version names) must follow semver semantics.

Resources