question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

netlify dev supports import() but building on Netlify doesn't

See original GitHub issue

Describe the bug

In development, the following code works as expected:

exports.handler = async function (event) {
  const myValue = await import('my-package');
  // ...
};

But when deploying to production, my-package doesn’t get bundled, resulting in 500 errors when the function tries to run (Cannot find package 'my-package' imported from /var/task/my-function.js)

To Reproduce

Steps to reproduce the behavior:

  1. Write a Netlify function with a dynamic import
  2. Run netlify dev
  3. See that the function runs properly
  4. Deploy to Netlify
  5. See that the deployed function doesn’t run

Expected behavior

Either Netlify’s production function bundling should support this case, or netlify dev should not. The behavior should match between the two.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mjswensencommented, Feb 16, 2022

Hi @eduardoboucas , sounds great, I’ll send that over now. Thanks!

0reactions
PH4NTOMikicommented, Feb 24, 2022

Possibly related #1036

Read more comments on GitHub >

github_iconTop Results From Across the Web

Netlify dev failing with "Cannot use import statement outside a ...
I'm new to your platform, but I've been using vercel for awhile, and haven't had any problems deploying on their site. I'm unable...
Read more >
[Support Guide] Netlify app builds locally but fails on deploy ...
I'm having issues with one of my sites. The build seems to be failing on an import line in one of my JS...
Read more >
Edge Functions netlify:edge include Doesn't Resolve Locally
The import from “netlify:edge” doesn't resolve locally. It does work with the Netlify CLI locally. But since one of the points of Typescript ......
Read more >
How do I import the Context type for local development with ...
json({ hello: "world" }); }; The import from “netlify:edge” doesn't resolve locally. It does work with the Netlify CLI locally. But since one...
Read more >
Sveltekit deployment doesn't seem to work - Support
My netlify site name: mellifluous-cranachan-5857d5.netlify.app Build problems? Link or paste the FULL build log & build settings screenshot ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found