Skip to content

Commit

Permalink
fix: Import custom identifier called css with error "Cannot find modu…
Browse files Browse the repository at this point in the history
…le 'linaria'" #739 (#740)

* fix: Import custom identifier called css with error "Cannot find module 'linaria'"
  • Loading branch information
GitaiQAQ committed Mar 20, 2021
1 parent f049a11 commit 07fb381
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/babel/src/utils/hasImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ const linariaLibs = new Set([
'linaria/react',
]);

const safeResolve = (name: string) => {
try {
return require.resolve(name);
} catch (err) {
return null;
}
};

// Verify if the binding is imported from the specified source
export default function hasImport(
t: any,
Expand Down Expand Up @@ -44,7 +52,7 @@ export default function hasImport(
// Otherwise try to resolve both and check if they are the same file
resolveFromFile(value) ===
(linariaLibs.has(source)
? require.resolve(source)
? safeResolve(source)
: resolveFromFile(source))
);

Expand Down

0 comments on commit 07fb381

Please sign in to comment.