-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected identifier? #19
Comments
This error isn't related to TypeScript, it's caused by specifically wrapping Gatsby's |
I investigated for hours and found that it was a webpack setup problem with gatsby. The problem will only happen with in detail: GatsbyJS provide an alias for @reach/router when stage is about web: https://github.com/gatsbyjs/gatsby/blob/8d66161e4b/packages/gatsby/src/utils/webpack.config.js#L405 So the result of Linaria loader uses it here: https://github.com/callstack/linaria/blob/0ddfc9bb8eba99fe7e0b54790b5cf47493e207ea/src/loader.js#L43 That's why there is We should find some way to make linaria ignore the alias or to make linaria understand es module syntax. |
Omg! 😵 Thanks! ❤️ Brainstorming: one way could be to create a Babel plugin that transforms |
Or just do forgery the linaria package on postinstall of gatsby-plugin-linaria? This is the simplest way I have right now Haha... |
@silvenon I just have done PoC of your idea. It would require two fixes:
const config = getConfig();
const routerAlias = config.resolve.alias['@reach/router'];
if (routerAlias) {
delete config.resolve.alias['@reach/router'];
config.resolve.alias['@reach/router$'] = routerAlias;
}
replaceWebpackConfig(config); Little hacky, but It would work without touching gatsby and linaria. Since the @reach/router's es package is completely separate, we can be sure that direct references to index.js always want the commonjs module. |
What do you mean by this? |
Ok, I wrote almost all of the code, but I later realized that transformation only happens once and babel plugin cannot be affected during evaluating.
Another similar version is:
probably this version would work... |
Just like callstack/linaria#392 (comment), we can use plugin's postinstall script to change linaria's behavior. |
The idea with the custom gatsby-link sounds like a more stable hack. Changing Linaria's behavior would break as soon as that code changes, if I understood correctly. |
Running into this issue as well. I see it's been a while since last activity here. Any chance of some progress on this? 🙏 |
Are there any working fixes/workarounds for this issue? |
Heyo! I'll check this out tomorrow, thanks for pinging 😉 |
Until I figure out a fix, a workaround is to simply wrap import { Link as GatsbyLink } from 'gatsby'
import { styled } from 'linaria/react'
const WrappedLink = (props) => <GatsbyLink {...props} />
const Link = styled(WrappedLink)`
/* your styles */
` I'll add this to the docs. |
Ok, workaround documented under "Known issues". Now the error says |
This workaround doesn't seem to work for me; if I have any component inside of So far, the only working temporary fix I have found is to be cognizant of which paths of my file tree end up referencing |
This happened because of the linaria's extractor doesn't understand the esmodule syntax. Removing the forced alias for I'm curious why that alias was needed in the first place. |
related with gatsbyjs/gatsby#13197 |
@jazevedo620 @deklanw @silvenon @sslotsky This has been fixed in v2.1.0. Please reopen the If it doesn't work for you |
Thanks for the fix! There is yet another error with the latest alpha Update: the error is related to |
Hey folks, looks like this is breaking Gatsby v3, as they've vendored |
I'm using TypeScript. Linaria is after TypeScript in my config.
The text was updated successfully, but these errors were encountered: