简体   繁体   中英

“Cannot find module” when deploying Node.js app to Google App Engine

I'm trying to deploy a simple Node.js express application to Google App Engine (flex environment).

The application runs great locally. When I try to deploy to App Engine, I get the following error:

Error: Cannot find module './app/models/xyz'

My app directory structure looks like:

server.js

app/models/xyz.js

In server.js , I require the xyz.js file as follows:

const Xyz = require('./app/models/xyz');

If I move the xyz.js file to the same root folder as server.js , everything deploys and works great.

This is the first node.js app that I try to deploy to Google App Engine. Do I need to configure the path to app/models/xyz.js in my app.yaml ? None of the reference applications seem to require this?

For small, simple projects, all the app's files can live in one directory. You are right, you may need to configure the path to "app/models/xyz.js" in your app.yaml, or rather using more than one *.yaml file, as described in the Organizing Configuration Files document.

I share your pain, I have the same issue and what is more a developer who is working separately has the same issue. Looks like it occurs after a big gcloud update.

Hope they will fix it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM