Closed dave-stevens-net closed 2 years ago
Hi @dave-stevens-net
Looks like @linaria/esbuild
in your project is resolved to lib
-version instead of esm
. Could you please provide a repo that reproduces that behaviour?
Node simply wont import the esm file:
import linaria from '@linaria/esbuild/esm/index.js';
> To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
Changing the @linaria/esbuild/esm/index.js
file extension to .mjs
allows me to import the ESM module.
In order for Node to choose a specific module system based on how the module is imported, some changes to the package.json is required:
https://nodejs.org/api/packages.html#dual-commonjses-module-packages
Here is a minimal repo that reproduces the issue: https://github.com/dsod/linaria-esbuild-import-issue
The change required is simply replacing this part of the package.json
file
"main": "lib/index.js",
"module": "esm/index.js",
with this:
"type": "module",
"exports": {
"import": "./esm/index.js",
"require": "./lib/index.js"
},
was tested locally and it works well
Fixed and released. Thank you @iMoses and @dsod!
Environment
Description
I followed your instructions on https://github.com/callstack/linaria/blob/master/docs/BUNDLERS_INTEGRATION.md#esbuild to add the
@linaria/esbuild
plugin to esbuild. However, when I add the import as follows it returns an object (containing thedefault
property) instead of the plugin function itself.The above logic produces the error,
TypeError: linaria is not a function
. I can get around this issue by coding the plugins as follows: