Skip to content
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

EvalError: tslib_1.__importStar is not a function #1209

Closed
layershifter opened this issue Feb 10, 2023 · 3 comments · Fixed by #1211
Closed

EvalError: tslib_1.__importStar is not a function #1209

layershifter opened this issue Feb 10, 2023 · 3 comments · Fixed by #1211
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided

Comments

@layershifter
Copy link
Contributor

Environment

  • Linaria version: @linaria/babel-preset@4.4.1
  • Bundler (+ version): N/A
  • Node.js version: Node 16
  • OS: N/A

Description

I checked the latest version on one of our projects and build there fails tslib_1.__importStar. In logs I noticed following:

2023-02-10T14:39:21.123Z linaria:module:00003 [code-cache] [] is missing ([ '__exportStar' ] were cached)
2023-02-10T14:39:21.123Z linaria:module:00003 [evaluated] get __importStar: undefined

Reproducible Demo

Note: I tried to build a smaller repro, but failed 🙃

EvalError: /home/projects/node-znzrvt/code/Button.js: tslib_1.__importStar is not a function in
| /home/projects/node-znzrvt/node_modules/@fluentui/react-icons/lib-cjs/icons/chunk-0.js
| /home/projects/node-znzrvt/node_modules/@fluentui/react-icons/lib-cjs/index.js
| /home/projects/node-znzrvt/code/Button.js

    at Module.evaluate (file:///home/projects/node-znzrvt/node_modules/@linaria/babel-preset/lib/module.js:362:13)
    at require.Object.assign.ensure (file:///home/projects/node-znzrvt/node_modules/@linaria/babel-preset/lib/module.js:302:13)
    at eval (file:///home/projects/node-znzrvt/node_modules/@fluentui/react-icons/lib-cjs/index.js:10:22)
    at eval (file:///home/projects/node-znzrvt/node_modules/@fluentui/react-icons/lib-cjs/index.js:103:3)
@layershifter layershifter added bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided needs: triage 🏷 Issue needs to be checked and prioritized labels Feb 10, 2023
@github-actions github-actions bot removed the needs: triage 🏷 Issue needs to be checked and prioritized label Feb 10, 2023
@layershifter
Copy link
Contributor Author

When it works:

2023-02-10T14:55:25.036Z linaria:module:00003 [evaluated] set __importStar: [Function: __importStar]
2023-02-10T14:55:25.036Z linaria:module:00003 [evaluated] set __importDefault: [Function: __importDefault]
2023-02-10T14:55:25.036Z linaria:module:00003 [evaluated] set __classPrivateFieldGet: [Function: __classPrivateFieldGet]
2023-02-10T14:55:25.036Z linaria:module:00003 [evaluated] set __classPrivateFieldSet: [Function: __classPrivateFieldSet]
2023-02-10T14:55:25.036Z linaria:module:00003 [evaluated] set __classPrivateFieldIn: [Function: __classPrivateFieldIn]
2023-02-10T14:55:25.036Z linaria:module:00003 [evaluated] get __exportStar: [Function: __exportStar]

When it fails:

2023-02-10T14:39:21.122Z linaria:module:00003 [code-cache] [] is missing ([ '__exportStar' ] were cached)
2023-02-10T14:39:21.122Z linaria:module:00003 [evaluated] get __exportStar: undefined

@juanferreras
Copy link
Contributor

@layershifter I'm not up to speed with how linaria is caching transformations but it does look like the tslib module is failing in your example (required by your code but also within the @fluentui/react-icons module)

it goes through this code path https://github.com/callstack/linaria/blob/master/packages/babel/src/module.ts#L414-L420 (a partial cache match?).

@Anber in this scenario, shouldn't it either...

  1. read again the code from filesystem: code = fs.readFileSync(filename, 'utf-8'); OR
  2. use the cached code?

What'd be the logic for not doing either? Apologies if I'm misunderstanding there!

I've tried it locally and seems both alternatives stop crashing this example

@Anber
Copy link
Collaborator

Anber commented Feb 16, 2023

@juanferreras, yep, you are right. The problem was that there was no code being executed in module.ts. This occurred when the file was not processed in previous stages, which happened for two reasons:

  1. re-exports through __exportStar were not being processed (and in general, the syntax tslib_1.something_there);
  2. node_modules was being ignored, so all its contents were not being transpiled and not being cached.

I've fixed the problem with __exportStar and also implemented your first approach with reread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants