Skip to content

Instantly share code, notes, and snippets.

@monzou

monzou/error.md Secret

Last active February 11, 2018 15:22
Show Gist options
  • Save monzou/10fb15080cfc746e5a0dea1ee15134bf to your computer and use it in GitHub Desktop.
Save monzou/10fb15080cfc746e5a0dea1ee15134bf to your computer and use it in GitHub Desktop.
Can't pass variables to styled-jsx with typescript
ERROR  Failed to compile with 1 errors                                                                                                                                                                                               00:21:39

 error  in ./pages/index.tsx

Syntax Error: <style jsx>{`some css`}</style>), but got BinaryExpression

  1 | import * as React from 'react';
  2 | var backgroundColor = '#eee';
> 3 | export default (function () { return (<div className='hello'>
    |                                       ^
  4 |     <p>Hello World</p>
  5 |     <style jsx>{"\n      .hello {\n        background-color: " + backgroundColor + ";\n        padding: 100px;\n        text-align: center;\n        transition: 100ms ease-in background;\n      }\n    "}</style>
  6 |   </div>); });



 @ multi ./pages/index.tsx
import * as React from 'react'
const backgroundColor = '#eee'
export default () => (
<div className='hello'>
<p>Hello World</p>
<style jsx>{`
.hello {
background-color: ${backgroundColor};
padding: 100px;
text-align: center;
transition: 100ms ease-in background;
}
`}</style>
</div>
)
const withTypescript = require('@zeit/next-typescript')
module.exports = withTypescript()
{
"name": "example",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"node-sass": "4.5.3",
"react": "16.0.0",
"react-dom": "16.0.0"
},
"license": "ISC",
"devDependencies": {
"@zeit/next-typescript": "0.0.8",
"typescript": "2.7.1"
}
}
{
"compileOnSave": false,
"compilerOptions": {
"target": "es5",
"module": "esnext",
"jsx": "preserve",
"allowJs": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": true,
"skipLibCheck": true,
"baseUrl": ".",
"typeRoots": [
"./node_modules/@types"
],
"lib": [
"dom",
"es2015",
"es2016"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment