martpie / next-transpile-modules

Next.js plugin to transpile code from node_modules. Please see: https://github.com/martpie/next-transpile-modules/issues/291
MIT License
1.13k stars 85 forks source link

Turborepo with custom server in Typescript fails during Heroku start after build, couldn't load next.config.js file #1825 #273

Closed clumsier closed 1 year ago

clumsier commented 1 year ago

Are you trying to transpile a local package or an npm package? Local/Turborepo setup

Describe the bug I'm currently trying to deploy starter from turborepo with mocked api path and custom server in Typescript on Heroku. Build + Start scripts are working locally atm. Build is proceeding without an issue, I've added `debug flag and got logs about transpiling during build step:

 web:build: info  - Creating an optimized production build...
 web:build: next-transpile-modules - transpiled: /tmp/build_f91b09fa/packages/ui/index.tsx
 web:build: next-transpile-modules - transpiled: /tmp/build_f91b09fa/packages/ui/Button.tsx
 web:build: next-transpile-modules - transpiled: /tmp/build_f91b09fa/packages/ui/index.tsx
 web:build: next-transpile-modules - transpiled: /tmp/build_f91b09fa/packages/ui/Button.tsx
  web:build: info  - Compiled successfully

when running start script on Heroku I got following logs:

2022-09-01T12:15:46.937949+00:00 heroku[web.1]: State changed from crashed to starting
2022-09-01T12:15:51.638783+00:00 heroku[web.1]: Starting process with command `npx turbo run start --filter=web`
2022-09-01T12:15:54.134361+00:00 app[web.1]: npm WARN exec The following package was not found and will be installed: turbo@1.4.3
2022-09-01T12:15:55.335677+00:00 app[web.1]:  WARNING  cannot find a .git folder. Falling back to manual file hashing (which may be slower). If you are running this build in a pruned directory, you can ignore this message. Otherwise, please initialize a git repository in the root of your monorepo
2022-09-01T12:15:55.343661+00:00 app[web.1]: • Packages in scope: web
2022-09-01T12:15:55.343667+00:00 app[web.1]: • Running start in 1 packages
2022-09-01T12:15:55.343872+00:00 app[web.1]: web:start: cache miss, executing ac805fbcaf77fe1d
2022-09-01T12:15:55.779425+00:00 app[web.1]: web:start: yarn run v1.22.19
2022-09-01T12:15:55.813586+00:00 app[web.1]: web:start: $ NODE_ENV=production node ./dist/index.js
2022-09-01T12:15:56.376153+00:00 app[web.1]: web:start: error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
2022-09-01T12:15:56.389930+00:00 app[web.1]: web:start: Done in 0.61s.
2022-09-01T12:15:56.402058+00:00 app[web.1]: 
2022-09-01T12:15:56.402102+00:00 app[web.1]:  Tasks:    1 successful, 1 total
2022-09-01T12:15:56.402115+00:00 app[web.1]: Cached:    0 cached, 1 total
2022-09-01T12:15:56.402137+00:00 app[web.1]:   Time:    1.102s 
2022-09-01T12:15:56.402140+00:00 app[web.1]: 
2022-09-01T12:15:56.631701+00:00 heroku[web.1]: State changed from starting to crashed

To Reproduce Clone my public repo https://github.com/clumsier/turborepo-test

Try to deploy on Heroku from main branch.

Expected behavior Server should start on heroku. (When I've removed next-transpile-modules) and usage of Button from UI lib I could get the deployment done. next.config.js was just

module.exports = {}

and it worked fine

Setup