I have created a Next js Project that I wanna publish as npm module. So I created it configuring tsup. Now I’m trying to use it in another project which I call consumer project that is also in Nextjs. I’m using it locally with help of npm link. Now I’m getting errors of useState in every component whereEver I used it there were few errors of useContext as well. So overall All its not able to identify React. Has someone encountered this kind of situation.
`{
"name": "mymodule",
"version": "0.1.0",
"private": true,
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"scripts": {
"dev": "next dev",
"build": "tsup",
"lint": "next lint",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"dependencies": {
"autoprefixer": "^10.4.19",
"axios": "^1.7.2",
"next": "14.2.4",
"react": "^18",
"react-dom": "^18",
"react-hook-form": "^7.52.1"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.6.0",
"@storybook/addon-essentials": "^8.1.11",
"@storybook/addon-interactions": "^8.1.11",
"@storybook/addon-links": "^8.1.11",
"@storybook/addon-onboarding": "^8.1.11",
"@storybook/blocks": "^8.1.11",
"@storybook/nextjs": "^8.1.11",
"@storybook/react": "^8.1.11",
"@storybook/test": "^8.1.11",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.4",
"eslint-plugin-storybook": "^0.8.0",
"postcss": "^8.4.39",
"storybook": "^8.1.11",
"tailwindcss": "^3.4.4",
"tsup": "^8.1.0",
"typescript": "^5"
},
"peerDependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2",
"next": "^12.0.0"
}
}
`
above is my module’s package json and below is consumer package json
`{
"name": "consumer",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "14.2.4",
"react": "^18.3.1",
"react-dom": "^18"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.4",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
}
`