Error From Node Modules Folder When Deploying From Github

I keep getting this error when trying to deploy from github: ‘deploying site’: Invalid filename ‘node_modules/es5-ext/reg-exp/#/sticky/is-implemented.js’. Deployed filenames cannot contain # or ? characters

Hi there @buffwire , You can’t have a # in a deployed the directory name! Can you clarify why you are deploying your node_modules? typically you wouldn’t do that since your frontend can’t consume it directly, rather it’s bundled in by webpack or other bundlers. You can also include them in your function deployments.

How do we exclude these from the deployment if our frontend is a directory down from the root directory?

hi @sschipke - what are you trying to exclude, exactly?

If you are trying to exclude the node modules, then regardless of where it is located, excluding it via the .gitignore should work.

as long as there is a package.json in the right place and all filepaths are correct, it shouldn’t really matter where in your directory tree the frontend files are located.

So in my root directory is basically my Express server. then in a client directory, I have my React app.

I have this code in the main app.js file for the server

if (process.env.NODE_ENV === "production") {
 app.user(express.static("client/build"));

 app.get("*", (req, res) => {
   res.sendFile(
     path.resolve(__dirname, "client", "build", "index.html")
   );
 });
}

then my postbuild script is this: "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client && cd client && rm -rf node_modules && cd .." but I cannot get my project to deploy correctly.

hi there, you won’t be able to deploy an express server to Netlify, I think that’s the crux of your issue:

That would be the heart of it. Thank you!

totally! Sorry it took us a moment to figure it out. But, on the upside, when it comes time to deploying a site that doesn’t use express, you’ll have some bona fide troubleshootin’ skills :wink:

1 Like