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

SyntaxError: Named export 'Minimatch' not found. #9935

Closed
1 task
JasonTame opened this issue Feb 1, 2024 · 10 comments · Fixed by #9955
Closed
1 task

SyntaxError: Named export 'Minimatch' not found. #9935

JasonTame opened this issue Feb 1, 2024 · 10 comments · Fixed by #9955
Assignees
Labels
needs response Issue needs response from OP

Comments

@JasonTame
Copy link

Astro Info

Astro                    v4.2.8
Node                     v18.17.0
System                   macOS (arm64)
Package Manager          npm
Output                   hybrid
Adapter                  @astrojs/node
Integrations             @astrojs/svelte
                         @astrojs/tailwind
                         @sanity/astro

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

After updating the @astro/vercel package to 7.1.0, I started getting 500 errors on Vercel with the error message:

file:///var/task/.vercel/output/_functions/entry.mjs:17
import { Minimatch } from 'minimatch';
         ^^^^^^^^^
SyntaxError: Named export 'Minimatch' not found. The requested module 'minimatch' is a CommonJS module, which may not support all module.exports as named exports.

Rolling back to 7.0.0 resolved the issue for now.

What's the expected result?

No 500 errors

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-9dype5

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Feb 1, 2024
@matthewp
Copy link
Contributor

matthewp commented Feb 1, 2024

Woops, let me take a look at that

@matthewp matthewp added the - P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority) label Feb 1, 2024
@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Feb 1, 2024
@matthewp
Copy link
Contributor

matthewp commented Feb 1, 2024

@JasonTame To clarify, do you get these errors when you deploy an app?

@matthewp
Copy link
Contributor

matthewp commented Feb 1, 2024

The stackblitz doesn't use Vercel. I went ahead and added it and deployed the app and did not receive an issue.

Minimatch is not used at runtime so that should be part of your built code. Can you explain more or update the example? Thanks.

@matthewp matthewp removed the - P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority) label Feb 1, 2024
@matthewp matthewp self-assigned this Feb 1, 2024
@matthewp matthewp added the needs response Issue needs response from OP label Feb 1, 2024
@JasonTame
Copy link
Author

@matthewp It builds and deploys fine, but when I access a route that is rendered via a serverless function, it bombs out when on v7.1.0. The full error displayed is:

file:///var/task/.vercel/output/_functions/entry.mjs:17
import { Minimatch } from 'minimatch';
         ^^^^^^^^^
SyntaxError: Named export 'Minimatch' not found. The requested module 'minimatch' 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 'minimatch';
const { Minimatch } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)
INIT_REPORT Init Duration: 287.82 ms	Phase: init	Status: error	Error Type: Runtime.ExitError
file:///var/task/.vercel/output/_functions/entry.mjs:17
import { Minimatch } from 'minimatch';
         ^^^^^^^^^
SyntaxError: Named export 'Minimatch' not found. The requested module 'minimatch' 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 'minimatch';
const { Minimatch } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)
INIT_REPORT Init Duration: 370.98 ms	Phase: invoke	Status: error	Error Type: Runtime.ExitError
Error: Runtime exited with error: exit status 1

I'm finding it challenging to reproduce the error, either locally or on a fresh astro install launched on Vercel, but I will keep trying today and revert back if I manage to do so.

@JasonTame
Copy link
Author

I see there was an issue raised on the minimatch repo that had the same error message. The suggestion was to run npm ls minimatch to check other versions of minimatch in the dependency tree. Here's the result if I run that locally:

├─┬ @astrojs/vercel@7.1.0
│ ├─┬ @vercel/nft@0.24.4
│ │ └─┬ glob@7.2.3
│ │   └── minimatch@3.1.2
│ └── minimatch@9.0.3
└─┬ tailwindcss@3.4.1
  └─┬ sucrase@3.35.0
    └─┬ glob@10.3.10
      └── minimatch@9.0.3

Perhaps minimatch@3.1.2 is being used somehow?

@ematipico
Copy link
Member

ematipico commented Feb 2, 2024

It's highly possible that that's the one picked up by the runtime. I raised an issue in the @vercel/nft repository to update their version of glob. Maybe you can mitigate the issue from your end by marking micromatch as external

@matthewp
Copy link
Contributor

matthewp commented Feb 2, 2024

@JasonTame did you try updating your lockfile? Maybe you have an old version of something.

@JasonTame
Copy link
Author

Thanks @ematipico @matthewp - adding minimatch as a dev dependency on my side resolved the issue, so it must have been using glob's version in prod.

@matthewp
Copy link
Contributor

matthewp commented Feb 2, 2024

That's good to know but you really shouldn't need to add dependencies that you don't directly depend on.

@JasonTame
Copy link
Author

100% - adding it as a dev dependency was a test to see if that was indeed the problem. I'll keep @astrojs/vercel locked at 7.0.0 until glob has been updated in vercel/nft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs response Issue needs response from OP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants