Rollup: Using the "styled" tag in runtime is not supported
See original GitHub issueEnvironment
rollup
: ^1.2.2
linaria
: ^1.3.1
Description
Project is TypeScript + Linaria transpiled via Babel using @babel/preset-typescript
. The module bundler I am using is rollup
. Despite having included the linaria/babel
preset in my babel.config.js
file I am still seeing an error in the console: Error: Using the "styled" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly.
Reproducible Demo
/**
* babel.config.js
*/
module.exports = {
presets: [
'@babel/preset-env',
'@babel/preset-typescript',
'@babel/preset-react',
'linaria/babel',
],
};
/**
* rollup.config.js
*/
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import linaria from 'linaria/rollup';
import css from 'rollup-plugin-css-only';
import pkg from './package.json';
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
const name = 'RollupTypeScriptBabel';
export default {
input: './src/index.ts',
external: ['react', 'react-dom'],
plugins: [
// Allows node_modules resolution
resolve({ extensions }),
// Allow bundling cjs modules. Rollup doesn't understand cjs
commonjs({
namedExports: {
'../../node_modules/linaria/react.js': ['styled'],
'../../node_modules/react-is/index.js': ['isElement', 'isValidElementType', 'ForwardRef'],
},
}),
// Compile TypeScript/JavaScript files
babel({ extensions, include: ['src/**/*'] }),
linaria({
sourceMap: process.env.NODE_ENV !== 'production',
evaluate: true,
}),
css({
output: 'styles.css',
}),
],
output: [
{
file: pkg.main,
format: 'cjs',
},
{
file: pkg.module,
format: 'es',
},
],
};
/**
* BasicImageViewer.tsx
*/
import { styled } from 'linaria/react';
const BasicImageViewer = styled.img`
width: 250px;
height: 250px;
`;
export default BasicImageViewer;
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:23 (12 by maintainers)
Top Results From Across the Web
styled-jsx is not enabled in rollup's project, it seems that babel ...
and I find that style tag is still in html, it seems that rollup don't load the babel config? Is there an error...
Read more >Styled-jsx-for-rollup - npm.io
Full, scoped and component-friendly CSS support for JSX (rendered on the server or the client). Code and docs are for v3 which we...
Read more >rollup.js
Rollup allows you to write your code using the new module system, and will then compile it back down to existing supported formats...
Read more >Linaria - Best of JS
Linaria currently supports webpack and Rollup to extract the CSS at build time. To configure your bundler ... Dynamic styles are not supported...
Read more >Releases - styled-components
breaking removed runtime prop validation functionality; use transient props for ... Support css tagged templates inside style objects, by @roginfarrer and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No problem, thanks for your help so far 👊
Whenever I get this resolved, if I think there is space for improvement, I will make a PR to the rollup section of the documentation 👍
@TMaszko So @tanphamhaiduong is on my team and we found a valid workaround - basically the issue is in the tsconfig - if you set your target to es6, it will strip out the Linaria template literals but if you set the target to ESNEXT, it will preserve them and the rollup plugin works fine with the typescript2 rollup plugin.
We are using the TSDX package to build our app, so this looks a bit janky as had to override the existing rollup config but hopefully the comments explain what is going on: https://github.com/reapit/foundations/blob/master/packages/elements/tsdx.config.js
Basically the plugin order we found worked was (pseudo code);
Hopefully helps!
BTW, really nice work on the library - was looking for ages for a CSS in JS solution that allows export to a static stylesheet as well as React Components. We distribute a UI lib to our users that exports both React Components and for non-react users, just a stylesheet. With the friendly output classes in the classNameSlug option, it’s absolutely the perfect tool for us - thanks for your work 💯