Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
566 views
in Technique[技术] by (71.8m points)

yarnpkg - How is `npm publish` different from `yarn publish`?

Is there a difference between yarn publish and npm publish? I have written a package, but for some reason, when I publish a new version using yarn publish I'm unable to import the package in my other projects. This is confusing because publishing withnpm publish results in working imports.

{
  "name": "@catpic/console-highlighter",
  "version": "0.1.6",
  "license": "MIT",
  "description": "Highlight console log messages with style.",
  "repository": {
    "type": "git",
    "url": "https://github.com/dlaub3/highlighter.git"
  },
  "directories": {
    "lib": "./lib"
  },
  "prepublish": "tsc -b",
  "main": "lib/index.js",
  "types": "lib/index.d.ts",
  "scripts": {
    "start": "parcel --out-dir serve index.html",
    "build": "tsc -b"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^4.11.0",
    "@typescript-eslint/parser": "^4.11.0",
    "eslint": "^7.16.0",
    "eslint-config-prettier": "^7.1.0",
    "eslint-plugin-prettier": "^3.3.0",
    "jest": "^26.6.3",
    "parcel-bundler": "^1.6.1",
    "prettier": "^2.2.1",
    "typescript": "^4.1.3"
  },
  "keywords": [
    "typescript",
    "javascript"
  ]
}
question from:https://stackoverflow.com/questions/65922489/how-is-npm-publish-different-from-yarn-publish

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In the end I needed to add the files field so that yarn would include the full contents of the lib folder.

 "files": [
    "lib/**/*"
  ],

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...