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

Recommended way to import methods from local modules in production? #45

Closed
mrlubos opened this issue Jan 12, 2020 · 4 comments
Closed

Comments

@mrlubos
Copy link

mrlubos commented Jan 12, 2020

Hey,

I have a Netlify function A located in functions/netlify-a/netlify-a.js. It relies on some method b() located in functions/helpers/b.js. This will work locally when running netlify dev, but won't work in production with the following message.

{
  errorType: "Runtime.ImportModuleError",
  errorMessage: "Error: Cannot find module '../helpers'↵Require stack:↵- /var/task/netlify-a.js↵- /var/runtime/UserFunction.js↵- /var/runtime/index.js",
  trace: ["..."]
}

I understand that helpers are not bundled during the build time. What's the recommended way to fix this issue? I am already running npm install on every function folder to install npm dependencies, how would I go about importing helper methods without publishing them as a separate npm package?

Thanks!

@mrlubos
Copy link
Author

mrlubos commented Jan 17, 2020

Wonder if either one of you can help @sw-yx @DavidWells? Thank you!

@DavidWells
Copy link

@mrlubos just sent you an email on how to opt into the netlify build beta. There are new function bundling updates in there that might solve this resolution issue.

Please let me know if it works

@mrlubos
Copy link
Author

mrlubos commented Jan 17, 2020

Will do, thank you for the quick reply @DavidWells!

@mrlubos
Copy link
Author

mrlubos commented Jan 17, 2020

Hey @DavidWells, I tried the beta build and I can happily confirm it works! 🎉

Very surprising I haven't come across anyone else mentioning this as I'd expect more people running Netlify Dev reusing common code in their Netlify Functions. Oh well...

Btw, do you have any front-end roles available at Netlify? 🧐

@mrlubos mrlubos closed this as completed Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants