[英]Using a peer dependency in npm package
我在一個充滿實用功能的 npm 包中將 momentjs 列為對等依賴項。 這些函數之一使用時刻。
"peerDependencies": {
"moment": "2.x.x"
},
下面是對使用 moment 的簡單介紹:
import moment from 'moment'
export default function formatDate(someDate) {
return moment(someDate).format('MM/DD/YYYY')
}
我的 package.json 看起來像這樣:
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsc",
"publish-free": "npm publish --access public"
},
當我運行“npm run build”時,我在終端中收到一條錯誤消息“找不到模塊‘時刻’”。
我目前正在通過使用 npm link 將它連接到我安裝了 moment 的主項目來測試包,但我無法通過構建階段。
只需將其安裝為依賴項即可。 為什么要將其安裝為 peerDependency?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.