[1.4.0-beta.0] A build error
This problem was reported by @Guria (#495)
Environment
Description
node_modules/react-scripts/node_modules/@babel/runtime/helpers/esm/taggedTemplateLiteral.js:1
export default function _taggedTemplateLiteral(strings, raw) {
^^^^^^
SyntaxError: Unexpected token 'export'
Reproducible Demo
@Guria could you please provide some details?
Will try to dig in and provide reproduction
After upgrading to 1.4.0-beta.0, seeing a the same (or at least, very similar) error message:
Module build failed (from ./node_modules/linaria/loader.js):
...\node_modules\react-dnd\dist\esm\index.js:1
export * from './common';
SyntaxError: Unexpected token export
at new Script (vm.js:83:7)
at Module.evaluate (...\node_modules\linaria\lib\babel\module.js:200:18)
at Module.<anonymous> (...\node_modules\linaria\lib\babel\module.js:184:13)
at Module.require (...\node_modules\linaria\lib\babel\module.js:134:23)
at ...\lib\components\Component2.js:32:17
at Script.runInContext (vm.js:133:20)
at Module.evaluate (...\node_modules\linaria\lib\babel\module.js:203:12)
at Module.<anonymous> (...\node_modules\linaria\lib\babel\module.js:184:13)
at Module.require (...\node_modules\linaria\lib\babel\module.js:134:23)
at...\lib\components\Component1.js:3:22
@ ../lib/components/MainView.js
@ ../lib/index.js
@ ./src/App.js
@ ./src/index.js
Not sure if @Guria is also seeing it from linaria loader? Seems to me that for some reason, babel is somehow getting confused when getting run through linaria, as both errors seem to be triggered by unrelated modules having ES6 code being included but not getting transpiled by babel?
filenames anonymized a bit; but the use case is basically nested, styled components (eg. const Component1 = styled.div'..'; const Component1 = styled(Component2)'..'; (and it works a-ok without that nesting) so seems like a possible regression from #343? Will try to get a better reproduction going as, well.
@Guria @matiasbuildops hi guys. Any news here?
@anber clean cra + linaria has no such problem. I am still wondering what is needed to add to reproduce this problem But I still have this problem on beta
@matiasbuildops could you try to describe your setup. Are you using yarn workspaces or something similar?
Hi @Guria!
I was not using yarn workspaces when I hit that but after investigating another issue relating to them (see #529), I think I might know what is causing at least my report - not sure if your error was raised in loader, as well? As these both seem to be somehow trying to import non-babelized files, I'm guessing both of these originate from the call to babel in transform.ts that only passes in linaria/loader as the presets and not what the user had defined in their babelrc or anything like that.
However, I'm really not at all sure why or when transform() actually gets called on files or whether this is/was a side-effect of other configuration so can't do more than a guess for now. Will try to investigate further when I have some time.
I can add one more datapoint, though. In my case, the problematic use was one module importing another module that was importing linaria. eg; all the problems happened when the code was running inside node_modules which is why I feel it could just be a side-effect of babel ignoring node_modules at some point above linaria? Not sure if that makes sense either but hey..
@matiasbuildops Hi. I have applied your patch and seems it works for me:
diff --git a/node_modules/linaria/lib/loader.js b/node_modules/linaria/lib/loader.js
index b6be4cf..44eaba0 100644
--- a/node_modules/linaria/lib/loader.js
+++ b/node_modules/linaria/lib/loader.js
@@ -68,7 +68,7 @@ function loader(content, inputSourceMap) {
};
result = (0, _transform.default)(content, {
- filename: this.resourcePath,
+ filename: _path.default.relative(process.cwd(), this.resourcePath),
inputSourceMap: inputSourceMap != null ? inputSourceMap : undefined,
outputFilename: outputFilename,
pluginOptions: rest,
@Anber could we release beta.1 with above patch?
@Guria probably, yes. I'll check regressions and build the next beta tomorrow.
it's weird. this patch works for me on local machine, but doesn't work on CI where it applied with patch-package
@Guria beta.2 has been released. Could you please check it?
Didn't worked unfortunately :(

Will try to investigate further
ok, I digged in a bit now. So it seems babel.transformFromAstSync fails to parse with following error for some of style files:
node_modules/@babel/runtime/helpers/esm/taggedTemplateLiteral.js:1
(function (exports) { export default function _taggedTemplateLiteral(strings, raw) {
^^^^^^
SyntaxError: Unexpected token 'export'
at new Script (vm.js:88:7)
at Module.evaluate (./node_modules/linaria/lib/babel/module.js:264:20)
at Module.Object.assign.ensure (./node_modules/linaria/lib/babel/module.js:177:15)
at ./web/desktop/VisitCardMultiService/styles.ts:10:54
at ./web/desktop/VisitCardMultiService/styles.ts:434:3
at Script.runInContext (vm.js:131:20)
at Module.evaluate (./node_modules/linaria/lib/babel/module.js:267:12)
at Module.Object.assign.ensure (./node_modules/linaria/lib/babel/module.js:177:15)
at ./web/desktop/VisitCardMultiService/ServiceRow/styles.ts:11:19
at ./web/desktop/VisitCardMultiService/ServiceRow/styles.ts:20:3 {
code: 'BABEL_TRANSFORM_ERROR'
}
I've checked the source of this files and common part for them is that they have import from another style.tsx file.
The only working patch I were succeded for now is replacing export default with module.exports = in node_modules/@babel/runtime/helpers/esm/taggedTemplateLiteral.js.
But I fill that isn't an appropriate solution :)
@Guria Could you please try that workaround https://github.com/callstack/linaria/issues/540#issuecomment-585228851?
I also have this problem. I have configured the following information in linaria.config.js to solve this problem. It seems that Linaria does not convert the content in node_modules by default. You need to specify it manually.
module.exports = {
ignore: /node_modules[\/\\](?!some-module|other-module)/
}
You can get more information here https://github.com/callstack/linaria/blob/master/docs/CONFIGURATION.md#options
I will try to reproduce it and see if it can be solved.
Fixed
just tried linaria@^2.0.0-alpha.5 and it builds without errors,