lambda-packages icon indicating copy to clipboard operation
lambda-packages copied to clipboard

ESM dependencies are not resolved correctly during build

Open Enteleform opened this issue 3 years ago • 16 comments

What version of astro are you using?

1.1.7

Are you using an SSR adapter? If so, which one?

no

What package manager are you using?

npm

What operating system are you using?

Windows

Describe the Bug

This error occurs during build when multi-distribution (CJS, ESM) packages are imported.

> astro build

06:04:41 AM [build] output target: static
06:04:41 AM [build] Collecting build info...
06:04:41 AM [build] Completed in 18ms.
06:04:41 AM [build] Building static entrypoints...
06:04:42 AM [build] Completed in 700ms.

 building client 
Completed in 202ms.


 generating static routes 
 error   Named export 'atom' not found. The requested module 'solid-use' is a CommonJS module, which may not support all module.exports as named exports. 
  CommonJS modules can always be imported via the default export, for example using:
  
  import pkg from 'solid-use';
  const { atom } = pkg;
  
file:///D:/DemoProject/dist/entry.mjs?time=1662717882730:3
/* empty css                        */import { atom } from 'solid-use';
                                               ^^^^
SyntaxError: Named export 'atom' not found. The requested module 'solid-use' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'solid-use';
const { atom } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:528:24)
    at async generatePages (file:///D:/DemoProject/node_modules/astro/dist/core/build/generate.js:70:20)
    at async staticBuild (file:///D:/DemoProject/node_modules/astro/dist/core/build/static-build.js:67:5)
    at async AstroBuilder.build (file:///D:/DemoProject/node_modules/astro/dist/core/build/index.js:82:5)
    at async AstroBuilder.run (file:///D:/DemoProject/node_modules/astro/dist/core/build/index.js:123:7)
    at async build (file:///D:/DemoProject/node_modules/astro/dist/core/build/index.js:22:3)
    at async runCommand (file:///D:/DemoProject/node_modules/astro/dist/cli/index.js:138:14)

I included two demos in the reproduction repo, one using astro and one using solid-start. Both demos are minimally modified starter projects, they were updated to implement atom from solid-use instead of createSignal from solid-js.

The solid-start demo builds without issue. (they also use vite in their build process)

The astro demo throws the above error.

solid-use has both CJS & ESM distributions, with a properly configured package.json that should allow usage in either environment.

Link to Minimal Reproducible Example

https://github.com/enteleform-codesandbox/0015--Astro--ESM-Imports

Participation

  • [ ] I am willing to submit a pull request for this issue.

Enteleform avatar Sep 09 '22 11:09 Enteleform