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

esbuild littered with sideEffect warnings #6291

Closed
1 task
j opened this issue Feb 17, 2023 · 13 comments · Fixed by #6531
Closed
1 task

esbuild littered with sideEffect warnings #6291

j opened this issue Feb 17, 2023 · 13 comments · Fixed by #6531
Assignees
Labels
- P1: chore Doesn't change code behavior (priority)

Comments

@j
Copy link

j commented Feb 17, 2023

What version of astro are you using?

2.0.14

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

Cloudflare / Vercel Edge

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug


~/code/dreary-dwarf ❯ npm run build 01:34:51 PM

[email protected] build
astro build

01:34:55 PM [content] Types generated 193ms
01:34:55 PM [build] output target: server
01:34:55 PM [build] deploy adapter: @astrojs/cloudflare
01:34:55 PM [build] Collecting build info...
01:34:55 PM [build] Completed in 445ms.
01:34:55 PM [build] Building server entrypoints...
01:34:55 PM [build] Completed in 0.83s.

finalizing server assets

01:34:55 PM [build] Rearranging server assets...
@astrojs/sitemap: Skipped!
No pages found! We can only detect sitemap routes for "static" builds. Since you are using an SSR adapter, we recommend manually listing your sitemap routes using the "customPages" integration option.

Example: sitemap({ customPages: ['https://example.com/route'] })

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

dist/$server_build/_worker.mjs:3:7:
  3 │ import 'path-to-regexp';
    ╵        ~~~~~~~~~~~~~~~~

"sideEffects" is false in the enclosing "package.json" file

node_modules/path-to-regexp/package.json:45:2:
  45 │   "sideEffects": false,
     ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

dist/$server_build/chunks/using-mdx.7c0ea41d.mjs:2:7:
  2 │ import 'path-to-regexp';
    ╵        ~~~~~~~~~~~~~~~~

"sideEffects" is false in the enclosing "package.json" file

node_modules/path-to-regexp/package.json:45:2:
  45 │   "sideEffects": false,
     ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

dist/$server_build/chunks/using-mdx.37588b9b.mjs:2:7:
  2 │ import 'path-to-regexp';
    ╵        ~~~~~~~~~~~~~~~~

"sideEffects" is false in the enclosing "package.json" file

node_modules/path-to-regexp/package.json:45:2:
  45 │   "sideEffects": false,
     ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

dist/$server_build/chunks/using-mdx.a13e8127.mjs:3:7:
  3 │ import 'path-to-regexp';
    ╵        ~~~~~~~~~~~~~~~~

"sideEffects" is false in the enclosing "package.json" file

node_modules/path-to-regexp/package.json:45:2:
  45 │   "sideEffects": false,
     ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

dist/$server_build/chunks/first-post.c0e02703.mjs:2:7:
  2 │ import 'path-to-regexp';
    ╵        ~~~~~~~~~~~~~~~~

"sideEffects" is false in the enclosing "package.json" file

node_modules/path-to-regexp/package.json:45:2:
  45 │   "sideEffects": false,
     ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

dist/$server_build/chunks/markdown-style-guide.bf35bf4d.mjs:2:7:
  2 │ import 'path-to-regexp';
    ╵        ~~~~~~~~~~~~~~~~

"sideEffects" is false in the enclosing "package.json" file

node_modules/path-to-regexp/package.json:45:2:
  45 │   "sideEffects": false,
     ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

dist/$server_build/chunks/second-post.4894b228.mjs:2:7:
  2 │ import 'path-to-regexp';
    ╵        ~~~~~~~~~~~~~~~~

"sideEffects" is false in the enclosing "package.json" file

node_modules/path-to-regexp/package.json:45:2:
  45 │   "sideEffects": false,
     ╵   ~~~~~~~~~~~~~

▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

dist/$server_build/chunks/third-post.b9f716b1.mjs:2:7:
  2 │ import 'path-to-regexp';
    ╵        ~~~~~~~~~~~~~~~~

"sideEffects" is false in the enclosing "package.json" file

node_modules/path-to-regexp/package.json:45:2:
  45 │   "sideEffects": false,
     ╵   ~~~~~~~~~~~~~

01:34:56 PM [build] Server built in 1.39s
01:34:56 PM [build] Complete!

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-kqoejc?file=astro.config.mjs

Participation

  • I am willing to submit a pull request for this issue.
@j
Copy link
Author

j commented Feb 17, 2023

The stackblitz link is using a minimal build.

Run npm run build and you'll get:

~/projects/github-kqoejc 30s
❯ npm run build
$ astro build
01:40:28 PM [content] No content directory found. Skipping type generation.
01:40:28 PM [build] output target: server
01:40:28 PM [build] deploy adapter: @astrojs/cloudflare
01:40:28 PM [build] Collecting build info...
01:40:28 PM [build] Completed in 565ms.
01:40:28 PM [build] Building server entrypoints...
01:40:29 PM [build] Completed in 0.75s.

 finalizing server assets 

01:40:29 PM [build] Rearranging server assets...
▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist.es2015/index.js" was marked as having no side effects [ignored-bare-import]

    dist/$server_build/_worker.mjs:4:7:
      4 │ import 'path-to-regexp';
        ╵        ~~~~~~~~~~~~~~~~

  "sideEffects" is false in the enclosing "package.json" file

    node_modules/path-to-regexp/package.json:45:2:
      45 │   "sideEffects": false,
         ╵   ~~~~~~~~~~~~~

01:40:30 PM [build] Server built in 2.46s
01:40:30 PM [build] Complete!

This happens I believe on any adapter that is outputting a bundle with esbuild.

The _worker.mjs file prior to going into esbuild has imports like this:

import { A as App, s as server_default, e as deserializeManifest } from './chunks/astro.9d6e56b8.mjs';
import { _ as _page0, a as _page1, b as _page2 } from './chunks/pages/all.4676f776.mjs';
import 'html-escaper';
import 'path-to-regexp';
import 'mime';
import 'cookie';
import 'kleur/colors';
import 'string-width';
import 'slash';

@jdbruxelles
Copy link

jdbruxelles commented Feb 18, 2023

Hi. Since I'm using SSR with netlify, I'm getting the following message when I run the server:

15:15:07 [astro] update .../.netlify/functions-serve/auth/src/netlify/functions/auth.js.map
▲ [WARNING] Ignoring this import because "node_modules/path-to-regexp/dist/index.js" was marked as having no side effects

    .netlify/functions-internal/entry.mjs:10:7:
      10 │ import 'path-to-regexp';
         ╵        ~~~~~~~~~~~~~~~~

  "sideEffects" is false in the enclosing "package.json" file

    node_modules/path-to-regexp/package.json:45:2:
      45 │   "sideEffects": false,
         ╵   ~~~~~~~~~~~~~

And my all-records.json.ts returns an empty array on the first request, then preloads content correctly. With and without the export const prerender = true; prop.

Astro: 2.0.14
Windows / Npm / Netlify function


Update

False Alarm. I think my issue is fixed with { eager: true } in import.meta.glob, but still get the side effects warnings.

@j
Copy link
Author

j commented Feb 18, 2023

Funny, I was importing via glob for our project and came across that issue as well.

But starting with a public Astro template and keeping it stock, you still get the warnings so something needs to be fixed.

@matthewp matthewp added the - P1: chore Doesn't change code behavior (priority) label Feb 21, 2023
@matthewp
Copy link
Contributor

@ematipico Is there anything we can do to silence these warnings?

@j
Copy link
Author

j commented Mar 12, 2023

@matthewp Unfortunately ended up deciding to switch to Next.js due to the uncertainty of deploying a potential broken build.

It shouldn't be a hard change to go back to Astro world, but seeing so many build errors in CI made us feel we can potentially do something that will actually break.

@jackcarey
Copy link

I'm getting the same error with Astro 2.1.2 and the Cloudflare Adapter. I tried removing the adapter and switching to a static build. npm run build then completed without issue, but Cloudflare doesn't seem to work at the moment to be able to push it live.

@jackcarey
Copy link

False Alarm. I think my issue is fixed with { eager: true } in import.meta.glob, but still get the side effects warnings.

@jdbruxelles How did you set the eager flag in your Astro config?

@jdbruxelles
Copy link

@jdbruxelles How did you set the eager flag in your Astro config?

Hi @jackcarey. I have set the eager property like this:

// In my src/pages/all-data.json.ts file (not astro.config.mjs)
const allAAAA = import.meta.glob("/public/data/AAAA/*.json", { eager: true });
const allBBBB = import.meta.glob("/public/data/BBBB/*.json", { eager: true });
const allData = [];

// Doing something with the data

export async function get({params, request}) {
  return {
    body: JSON.stringify(allData)
  };
}

See the documentation of Vite Glob Import for more information.

@matthewp
Copy link
Contributor

These warnings are caused by double-building. We build with Vite which does not remove imports for packages with sideEffects: false, but esbuild does. And esbuild warns about it. In the case of Cloudflare and Netlify, they are both getting a second build. These warnings can be ignored. But we should silence them to prevent confusion.

@susickypavel
Copy link

I see similar warnings using Vercel adapter with edge functions (serverless is ok). Should I try to make a repro or separate issue?

@jamesli2021
Copy link

@susickypavel This is closed, create new issue.

@kasvith
Copy link

kasvith commented Aug 12, 2023

im having the same issue with vercel edge adapter

@x71c9
Copy link

x71c9 commented Aug 14, 2023

I managed to remove the warning by adding:

export default defineConfig({
  ...
  vite: {
    ssr: {
      noExternal: ['path-to-regexp'],
    },
  },
  ...
})

to my astro.config.mjs

@x71c9 x71c9 mentioned this issue Aug 14, 2023
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P1: chore Doesn't change code behavior (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants