I have momentjs listed as a peer dependency in a npm package full of utility functions. One of these functions uses moment.
"peerDependencies": {
"moment": "2.x.x"
},
Here's a simplified look at where moment is being used:
import moment from 'moment'
export default function formatDate(someDate) {
return moment(someDate).format('MM/DD/YYYY')
}
My package.json looks like this:
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsc",
"publish-free": "npm publish --access public"
},
When I run "npm run build" I get an error in the terminal saying "Cannot find module 'moment'".
I am currently testing the package by using npm link to connect it to my main project where I have moment installed but I can't get past the build stage.