jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.29k stars 507 forks source link

Styled-components does not bundle with my library when I ship it to npm #1144

Closed GodsonAddy closed 2 years ago

GodsonAddy commented 2 years ago

Current Behavior

So I built a library and published it to npm using tsdx(react,typescript and storybook) + styled-components. After building the library I published it to npm via np and it was a success. But the issue is when I install that npm package which I published to npm(flashcardui) into another application I get this error

`ERROR in ./node_modules/flashcardui/dist/flashcardui.esm.js 2:0-54

Module not found: Error: Can't resolve 'styled-components' in 'C:\Users\user-name\my-application-name\node_modules\flashcardui\dist'`

Suggested solution(s)

I was able to solve this issue by

run "npm i styled-components" in my terminal and then "npm start" OR delete package-lock.json and node_modules, after that run "npm install"

But I think there's a better solution for this issue because you should not always install this package alongside styled-components. That's not the best

Additional context

Your environment

"devDependencies": { "@babel/core": "^7.18.5", "@mdx-js/react": "^2.1.2", "@size-limit/preset-small-lib": "^7.0.8", "@storybook/addon-a11y": "^6.5.9", "@storybook/addon-essentials": "^6.5.9", "@storybook/addon-info": "^5.3.21", "@storybook/addon-links": "^6.5.9", "@storybook/addons": "^6.5.9", "@storybook/builder-webpack5": "^6.5.9", "@storybook/manager-webpack5": "^6.5.9", "@storybook/mdx2-csf": "^0.0.3", "@storybook/react": "^6.5.9", "@types/jest": "^28.1.3", "@types/react": "^18.0.14", "@types/react-dom": "^18.0.5", "@types/styled-components": "^5.1.25", "babel-loader": "^8.2.5", "chromatic": "^6.6.4", "husky": "^8.0.1", "jest": "^28.1.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-is": "^18.2.0", "size-limit": "^7.0.8", "storybook-dark-mode": "^1.1.0", "styled-components": "^5.3.5", "tsdx": "^0.14.1", "tslib": "^2.4.0", "typescript": "^4.7.4" },

To be able to get this issue, run

GodsonAddy commented 2 years ago

Found this on Styled-Components. I guess it answers my question :

https://styled-components.com/docs/faqs#i-am-a-library-author-should-i-bundle-styledcomponents-with-my-library