callstack / linaria

Zero-runtime CSS in JS library
https://linaria.dev
MIT License
11.41k stars 413 forks source link

Cannot import npm package use linaria. #1075

Closed nguyenabc closed 1 year ago

nguyenabc commented 1 year ago

Environment

localhost

Description

Hi everyone, I build design system with storybook, typescript and linaria. I already publish package on gitlab, but when I import into another project it get the issue:

image image

My config for linaria in .babelrc and config-overrides.json: { "presets": [ [ "react-app", { "flow": false, "typescript": true, "runtime": "automatic" } ], "@babel/preset-env", "@babel/preset-react", "@linaria" ] }

/ eslint-disable react-hooks/rules-of-hooks / const { useBabelRc, override, addWebpackModuleRule, addWebpackAlias, addWebpackResolve, } = require('customize-cra') const path = require('path')

module.exports = override( useBabelRc(), addWebpackModuleRule({ test: /.(js|tsx)$/, use: [ { loader: 'babel-loader' }, { loader: '@linaria/webpack-loader', options: { cacheDirectory: 'src/.linaria_cache', sourceMap: process.env.NODE_ENV !== 'production', }, }, ], exclude: '/node_modules/', }), addWebpackResolve({ extensions: ['.tsx', '.ts', '.js'], mainFiles: ['index'], }), addWebpackAlias({ '@stories': './src/stories', '@linaria/core': path.join(__dirname, './node_modules/@linaria/core/lib'), }), )

As understand, I think linaria don't run in the runtime. So, i don't know why it's not working when I import into another react app. Have anyone help me to explain and gimme instruction to build npm package registry for react app+ storybook + linaria?

Thank you very much.

Reproducible Demo

nguyenabc commented 1 year ago

Please have anyone to help me?

nguyenabc commented 1 year ago

@need:help

nguyenabc commented 1 year ago

Don't have anybody help to resolve.

Anber commented 1 year ago

Hi @nguyenabc

Since Storybook uses webpack as a bundler, you have to add @linaria/webpack4-loader or @linaria/webpack5-loader to its config https://storybook.js.org/docs/react/builders/webpack#extending-storybooks-webpack-config

Anber commented 1 year ago

And if you want to publish your design system as a package with compiled styles, you should take a look at @linaria/cli.

nguyenabc commented 1 year ago

Thank for your support @Anber . But I roll back to use styled-components and use rollup. They are easier to build package.