Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

build.command fail for netlify functions #1167

Open
Gresliebear opened this issue Aug 7, 2022 · 9 comments
Open

build.command fail for netlify functions #1167

Gresliebear opened this issue Aug 7, 2022 · 9 comments
Labels
question Further information is requested

Comments

@Gresliebear
Copy link

Gresliebear commented Aug 7, 2022

I am deploying redwood graphql server on netlify via their deploy script netlify.toml

I get error its unable to access the imports or modules outside of the fuction server I have tried glob and direct include file without success.

Runtime.ImportModuleError - Error: Cannot find module '..\..\lib\auth' Require stack: - /var/task/api/dist/directives/requireAuth/requireAuth.js - /var/task/api/dist/functions/graphql.js - /var/task/graphql.js - /var/runtime/index.mjs

so at build at it builds the functions code but that code is accessing code outside of itself as shown in this tree, its trying acess imports from the lib folder but Cannot find it so I think its not bundling the other dist files

image

image

this is my netlify.toml file

[build]
command = "yarn rw deploy netlify"
publish = "web/dist"
functions = "api/dist/functions"
included_files = ["api/dist/*.js"]
# included_files = ["api/dist/directives/*"]
# included_files = ["api/dist/graphql/*"]
# included_files = ["api/dist/lib/*"]
# included_files = ["api/dist/services/*"]

# [functions]
# directory = "api/dist/"
  # [functions.directory2]
  #   directory2 = "api/dist/lib"
[dev]
  # yarn rw build --verbose && yarn rw prisma migrate deploy && yarn rw data-migrate up
  # To use [Netlify Dev](https://www.netlify.com/products/dev/),
  # install netlify-cli from https://docs.netlify.com/cli/get-started/#installation
  # and then use netlify link https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
  # to connect your local project to a site already on Netlify
  # then run netlify dev and our app will be accessible on the port specified below
  framework = "redwoodjs"
  # Set targetPort to the [web] side port as defined in redwood.toml
  targetPort = 8910
  # Point your browser to this port to access your RedwoodJS app
  port = 8888

[[redirects]]
  from = "/*"
  to = "/200.html"
  status = 200

@Gresliebear
Copy link
Author

my real question is can zip-it-and-ship-it build scripts up the tree I.E. outside its directory or even subdirectories. can it build node_modules at all?

@danez
Copy link
Contributor

danez commented Aug 8, 2022

Is this error happening during bundling or when trying to run the function?
It is really hard to help without being able to really look at anything, but I made two observations. It looks like you are using ESM modules, because I see the *.mjs extension in the stacktrace. If this is the case, then ESM always requires file extensions for relative imports, but ..\..\lib\auth does not have a file extension. The second thing I noticed is that the import in question: ..\..\lib\auth contains backslashes, worth trying to use forward slashes?

And yes zip-it-and-ship-it should be able to have files being imported from outside the functions dir and node_modules.

@danez danez added the question Further information is requested label Aug 8, 2022
@Gresliebear
Copy link
Author

Is this error happening during bundling or when trying to run the function? It is really hard to help without being able to really look at anything, but I made two observations. It looks like you are using ESM modules, because I see the *.mjs extension in the stacktrace. If this is the case, then ESM always requires file extensions for relative imports, but ..\..\lib\auth does not have a file extension. The second thing I noticed is that the import in question: ..\..\lib\auth contains backslashes, worth trying to use forward slashes?

And yes zip-it-and-ship-it should be able to have files being imported from outside the functions dir and node_modules.

it happens when the function is deployed here is a photo

image

@Gresliebear
Copy link
Author

Is this error happening during bundling or when trying to run the function? It is really hard to help without being able to really look at anything, but I made two observations. It looks like you are using ESM modules, because I see the *.mjs extension in the stacktrace. If this is the case, then ESM always requires file extensions for relative imports, but ..\..\lib\auth does not have a file extension. The second thing I noticed is that the import in question: ..\..\lib\auth contains backslashes, worth trying to use forward slashes?

And yes zip-it-and-ship-it should be able to have files being imported from outside the functions dir and node_modules.

is there a example importing files outside of functions folder I have not found a working one and I tried many variations

@danez
Copy link
Contributor

danez commented Aug 18, 2022

included_files is using glob and included_files = ["api/dist/*.js"] matches api/dist/file.js but not api/dist/subfolder/file.js

What you probably want is included_files = ["api/dist/**/*.js"]. ** is called the globstar which matches everything even folders, and subfolders. Some description here.

@Gresliebear
Copy link
Author

I am still getting error on the serverless function same error Invocation failed I restructured my application and its not working

image

@danez
Copy link
Contributor

danez commented Aug 22, 2022

I just noticed that your included_files option is in the wrong section, so it should look like

[build]
command = 
publish = 

[functions]
directory = "api/dist/functions"
included_files = ["api/dist/**/*.js"]

Does that help?

Here are the docs: https://docs.netlify.com/configure-builds/file-based-configuration/#functions

@Gresliebear
Copy link
Author

Gresliebear commented Aug 22, 2022 via email

@Gresliebear
Copy link
Author

@danez I found out basically Your Netlify CLI doesn't work for Windows & MacOS system files or paths only if I was on Linux system. the serverless function is completely broken if I build off of a windows Netlify.toml file

"Problems arise with some package locations and how the list in bundled ... but the biggest issue is that the Prisma client will build using Windows or OSX and Netlfiy deploys need a linux variant." here I working with Redwood dev redwoodjs/redwood#6260

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants