Skip to content

[Bug]: Netlify deploy failing due to missing netlify-handler.js #8379

@azinod

Description

@azinod

Version

System:
    OS: macOS 15.7.4
    CPU: (14) arm64 Apple M3 Max
    Memory: 301.03 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 145.0.7632.110
    Edge: 145.0.3800.70
    Firefox: 147.0.4
    Safari: 26.3
  npmPackages:
    @modern-js/app-tools: 3.0.2 => 3.0.2 
    @modern-js/runtime: 3.0.2 => 3.0.2 
    @modern-js/server-runtime: 3.0.2 => 3.0.2 
    @modern-js/tsconfig: 3.0.2 => 3.0.2

Details

We started getting issues to deply to Netlify after upgrading to v3.0.2

When I run MODERNJS_DEPLOY=netlify npx modern deploy, the generated output files in .netlify/functions include a netlify-handler.cjs, however when I deploy to netlify the function initalization fails because it is looking for netlify-handler.js (regular JS file, not CJS)

I am guessing the issue might have to do with the line below that tries to import netlify-handler.js instead of netlify-handler.cjs

let handlerCode = (
await fse.readFile(path.join(__dirname, './netlify-handler.js'))
).toString();

This is the error I get:

Feb 25, 02:55:57 PM: ERROR  Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module './netlify-handler.js'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module './netlify-handler.js'","Require stack:","- /var/task/index.js","- /var/runtime/index.mjs","    at _loadUserApp (file:///var/runtime/index.mjs:1192:17)","    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1235:21)","    at async start (file:///var/runtime/index.mjs:1454:23)","    at async file:///var/runtime/index.mjs:1464:1"]}

Can you please check?

Reproduce link

Don't have one yet

Reproduce Steps

To test this, you need to setup a new project and a netlify app and test deploy to netlify using this build command: MODERNJS_DEPLOY=netlify npx modern deploy

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions