lerna import always returns EDESTDIR - node.js

I have a pre-existing project that I'd like to import into my existing lerna monorepo that uses yarn workspaces.
Command(s):
I've tried running all of the following commands. The error remains stubbornly unchanged. Also, petstore has a package.json file and is a git repo.
lerna import ./petstore --dest="./packages/"
lerna import ./petstore --dest="./packages/api/"
ERROR:
lerna notice cli v3.20.2
lerna ERR! EDESTDIR --dest does not match with the package directories: packages/**
Also, lerna import ../petstore results in a packages/**/petstore being created which is not an expected result.
I hope this consists of all the relevant code. We have supporting packages under packages/shared and apis under packages/api.
lerna.json
{
"packages": [
"packages/**/*"
],
"npmClient": "yarn",
"useWorkspaces": true,
"private": true,
"version": "0.0.1",
"lerna": "2.11.0"
}
package.json
{
"name": "root",
"devDependencies": {
"lerna": "^2.11.0"
},
"workspaces": [
"packages/**/*"
],
}
Resources I have looked at:
Lerna troubleshooting page but it does not have any info on this error.
Lerna Github Issue #1872
Lerna Github Issue #1197
Lerna Slack Link Broken

Lerna reads the packages from the key workspaces on package.json instead of the packages on lerna.json.
lerna reads all the values with a /* and considers them package directories. It interprets ** literally and does not parse it as a wildcard and expand it.
The solution is to remove packages from lerna.json:
{
"npmClient": "yarn",
"useWorkspaces": true,
"private": true,
"version": "0.0.1",
"lerna": "2.11.0"
}
and update the workspaces path to refer to any sub-directories in your packages explicitly if your monorepo is structured that way:
{
"name": "root",
"devDependencies": {
"lerna": "^2.11.0"
},
"workspaces": [
"packages/a/*",
"packages/api/*"
],
}
To import the pet-store project into packages/api in the monorepo from a directory outside the mono-repo:
lerna import ../pet-store --dest="./packages/api/"

Related

Package is not publishing to npm (not in the npm registry)

I would like to publish my git repository to npm so I can use it in other projects. But when I run the npm publish command I get the following error:
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://npm.pkg.github.com/vue-toggle-component
npm ERR! 404
npm ERR! 404 'vue-toggle-component#0.1.0' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\niels\AppData\Roaming\npm-cache\_logs\2020-10-29T10_47_26_952Z-debug.log
When trying to bugfix, I have tried the npm adduser command and the npm login command to make sure I logged in. Both of these did not solve my problem since it looked like I was already logged in.
My package.json:
{
"name": "vue-toggle-component",
"version": "0.1.0",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^2.6.11"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
],
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
},
"description": "## Project setup ``` yarn install ```",
"main": "babel.config.js",
"repository": {
"type": "git",
"url": "git+https://github.com/nehlis/vue-toggle-component.git"
},
"keywords": [
"Vue.js",
"Toggle",
"component",
"Lightweight",
"Checkbox"
],
"author": "Niels Bosman",
"license": "ISC",
"bugs": {
"url": "https://github.com/nehlis/vue-toggle-component/issues"
},
"homepage": "https://github.com/nehlis/vue-toggle-component#readme"
}
Does anyone know how to fix this?
Try npm login. In case of npm publish, sometimes misleading message is shown.
Based on the https://npm.pkg.github.com/ appearing in the error output, you are trying to publish to GitHub Packages and not the npm registry (which are still separate, although GitHub now owns npm). According to the GitHub packages docs:
GitHub Packages only supports scoped npm packages. Scoped packages have names with the format of #owner/name. Scoped packages always begin with an # symbol. You may need to update the name in your package.json to use the scoped name. For example, "name": "#codertocat/hello-world-npm".
So you'll need to either change your configuration to point to the npm registry rather than the GitHub packages registry, or else change the name field in your package.json to be a scoped package name.
I have the same issue the problem comes from the published package is not accessible so you will need to add .npmrc with your private repo to be like this
registry=https://npm.pkg.github.com/yourcompany
or
#yourcompany:registry=https://npm.pkg.github.com
As another user mentioned you have to add yourself to the private registry of your company or organization. But if you don't have your .npmrc setup, this command will create the file automatically as well as update your registry:
npm config set registry https://registry.your-company-registry.npme.io/
However the most robust way is to simply do
npm login
It's all about authentication.
Seems like username/password auth is no more working with npm publish.
You need to generate Access Token
Then use it to publish
NPM_TOKEN=blahblahblahblaha npm publish
In the .npmrc file add the below code
always-auth = true
#your_company:registry=https://npm.artifactory.your_company.com/artifactory/api/npm/npm/
registry=https://npm.artifactory.your_company.com/artifactory/api/npm/npm/
In GIT bash execute command
npm config set registry https://registry.npmjs.org/
npm install
I faced the same problem and used almost all the valid solutions that I felt
If you published it on GitHub then this could be something that could help you.
like
updating npm to the latest version
setting registry using
npm config set registry https://registry.your-company-registry.npme.io/
resetting token
It still didn't work
If you have uppercase characters in your GitHub username, and if you are using the command provided by GitHub under the package section
Make sure to update your username when you run that command locally
By default, GitHub does not show uppercase characters in the command under the packages section.
So if your user name is UserName123 and package name is my-first-package
the command that GitHub will show is
npm install #username123/my-first-package#1.0.0
see that the username is case-sensitive when you install a package
hence, update your command to
npm install #Username123/my-first-package#1.0.0
and hopefully it should work fine

Publishing NPM package with np throws error with exit code 128 (Gatsby & rollup)

I've had no problems manually publishing my scoped package to the NPM registry however I found the np module could be used to ensure no steps were skipped in the process.
I've configured only a couple options in my package.json as the defaults are otherwise sensible for me. (This is the package.json for the npm package itself)
{
"name": "#scope/package",
"version": "0.0.6",
"description": "blah",
"main": "index.js",
"scripts": {
"prepublishOnly": "npm run release",
"release": "npm run build:dev && npm run build:prod",
"build:prod": "NODE_ENV=production rollup -c",
"build:dev": "NODE_ENV=development rollup -c",
"test": "echo \"No tests specified\""
},
"repository": {
"type": "git",
"url": "http://blah/blah/blah"
},
"author": "blah",
"license": "ISC",
"devDependencies": {
...
},
"peerDependencies": {
...
},
"np": { <----
"yarn": false, <----
}, <----
"publishConfig": { <----
"access": "public" <----
} <----
}
Unfortunately when I run np I receive the error:
Command failed with exit code 128 (Unknown system error -128): git log --format=%s %h commit sha commit sha..HEAD
The first commit sha is the initial commit from Gatsby.
If you've used Gatsby you may have seen it:
Initial commit from gatsby: (https://github.com/gastbyjs/gatsby-starter-hello-world.git)
For context: I'm creating a component library where the parent dir is setup using GatsbyJS so that I can use it for the demo site while the child dirs under src/packages will be the individual components that will be published to the npm registry. So the demo site is bundled with Gatsby while the packages are bundled using rollup.
Why am I receiving this -128 error code and how do I fix it?

Visual Code Run Build Task npm

I'm using Visual Studio Code 1.13.0 on Windows 10.
I have the following build script in my package.json:
{
//omitted other props
"scripts": {
"build": "webpack"
}
}
I've installed webpack with npm install --global webpack, so it's installed globally.
The webpack.config.js is irrelevant for my question.
When I run npm run build in the terminal, everything works fine. But when I run the Visual Code Tasks: Run Build Task (ctrl+shift+b or ctrl+shift+p > Run Build Task), then I'm getting the following message in the output window:
'"npm run build"' is not recognized as an internal or external
command, operable program or batch file.
Why? (using npm version: 3.10.10)
You should create tasks.json file and specify build task with npm task runner as described here ctrl+shift+p > Configure Task Runner. In your case task.json file should looks something like that
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"showOutput": "always",
"suppressTaskName": true,
"tasks": [
{
"isBuildCommand": true,
"taskName": "build",
"args": ["run", "build"]
}
]
}
tasks.json can be used for running multiple different tasks. This is #oleg-m's answer updated for version 2 of tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type":"npm",
"script": "build",
"group": "build"
}
]
}

Browserify and bower. Canonical approach

The way I'm using packages that not available out of the box in npm, right now is like that:
package.json has:
"napa": {
"angular": "angular/bower-angular",
"angular-animate": "angular/bower-angular-animate",
"d3": "mbostock/d3",
"ui-router":"angular-ui/ui-router",
"bootstrap":"twbs/bootstrap"
},
"scripts": {
"install": "node node_modules/napa/bin/napa"
and that installs files into node_modules directory, and I use them natively like this
require('angular/angular')
require('ui-router')
... etc
That works, but I was thinking if it's possible to use packages installed with bower (into bower specific folder) and use them natively as node modules? Is it possible to tweak node's module resolution and force it to look for modules not just inside node_modules directory, but also in bower directory as well? Or maybe using npm link or whatever?
Is there some sort of convention to use browserify with bower?
You can try to install via debowerify
The package.json may then look as follows:
{
"name": "browserify-begin",
"version": "0.0.0",
"dependencies": {
},
"browserify": {
"transform": [
"debowerify"
]
},
"devDependencies": {
"browserify": "^4.1.5",
"debowerify": "^0.7.1",
"grunt": "^0.4.5"
}
}
Given angular is installed with
bower install angular
Then within the js file will be as follows:
require("angular");
You can use browserify-shim and configure the bower-installed modules in your package.json like this:
"browser": {
"angular": "./bower_components/angular/angular.js",
"angular-resource": "./bower_components/angular-resource/angular-resource.js"
},
"browserify-shim": {
"angular": {
"exports": "angular"
},
"angular-resource": {
"depends": ["./bower_components/angular/angular.js:angular"]
}
},
Then your code can require them by their short name as if there were regular npm modules.
Here is the spec for the "browser" package.json property.

NPM and Git Respository field missing but I have one in the package.json

This is my NPM Package JSON, the Git Repository is defined in the json. It is a password protected on hosted at Kiln. But NPM still complains of a repository field missing ?
This is the error
npm WARN package.json dateformat#1.0.2-1.2.3 No repository field.
And this is the contents of my package.json
{
"name": "Pocket-to-Pocket",
"version": "1.0.0",
"description": "Card Management App For PFS",
"main": "Gruntfile.js",
"scripts": {},
"repository": {
"type": "git",
"url": "https://nyx.kilnhg.com/Code/Prepaid-Financial-Services/Group/Pocket-to-Pocket.git"
},
"author": "Nyx Digital",
"license": "All Rights Reserved.",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-imageoptim": "~1.2.12"
}
}
That warning is a dependency warning, and just means that the package dateformat for version 1.0.2-1.2.3 has no repository field. This doesn't affect your application, and it isn't an error, just a warning.
You can check this, as your application depends on Grunt, and Grunt depends on dateformat#1.0.2-1.2.3. By checking the GitHub repository, you can see that the repository field for dateformat wasn't added until after version 1.2.3. The commit is here.

Resources