blitz-js / babel-plugin-superjson-next

Automatically transform your Next.js Pages to use SuperJSON
MIT License
125 stars 15 forks source link

Error: Cannot find module 'babel-plugin-superjson-next/tools' #43

Closed alexfinnarn closed 3 years ago

alexfinnarn commented 3 years ago

Locally, I don't see any issues, but after I build my project on Heroku, I get this error:

 Resolving node version 14.x...
 Downloading and installing node 14.15.5...
 Using default npm version: 6.14.11
 Resolving yarn version 1.22.x...
 Downloading and installing yarn (1.22.10)
 Installed yarn 1.22.10

yarn start...

2021-02-15T23:25:38.650117+00:00 app[web.1]: Error: Cannot find module 'babel-plugin-superjson-next/tools'
2021-02-15T23:25:38.650126+00:00 app[web.1]: Require stack:
2021-02-15T23:25:38.650152+00:00 app[web.1]: - /app/.next/server/pages/index.js
2021-02-15T23:25:38.650153+00:00 app[web.1]: - /app/node_modules/next/dist/next-server/server/require.js
2021-02-15T23:25:38.650154+00:00 app[web.1]: - /app/node_modules/next/dist/next-server/server/load-components.js
2021-02-15T23:25:38.650154+00:00 app[web.1]: - /app/node_modules/next/dist/next-server/server/api-utils.js
2021-02-15T23:25:38.650155+00:00 app[web.1]: - /app/node_modules/next/dist/next-server/server/next-server.js
2021-02-15T23:25:38.650155+00:00 app[web.1]: - /app/node_modules/next/dist/server/next.js
2021-02-15T23:25:38.650155+00:00 app[web.1]: - /app/server.js
2021-02-15T23:25:38.650156+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
2021-02-15T23:25:38.650156+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:952:19)
2021-02-15T23:25:38.650157+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:88:18)
2021-02-15T23:25:38.650157+00:00 app[web.1]: at Object.is+Z (/app/.next/server/pages/index.js:2613:18)
2021-02-15T23:25:38.650157+00:00 app[web.1]: at __webpack_require__ (/app/.next/server/pages/index.js:23:31)
2021-02-15T23:25:38.650157+00:00 app[web.1]: at Module.23aj (/app/.next/server/pages/index.js:212:91)
2021-02-15T23:25:38.650158+00:00 app[web.1]: at __webpack_require__ (/app/.next/server/pages/index.js:23:31)
2021-02-15T23:25:38.650158+00:00 app[web.1]: at Object.10 (/app/.next/server/pages/index.js:192:18)
2021-02-15T23:25:38.650158+00:00 app[web.1]: at __webpack_require__ (/app/.next/server/pages/index.js:23:31) {
2021-02-15T23:25:38.650158+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-02-15T23:25:38.650159+00:00 app[web.1]: requireStack: [
2021-02-15T23:25:38.650159+00:00 app[web.1]: '/app/.next/server/pages/index.js',
2021-02-15T23:25:38.650159+00:00 app[web.1]: '/app/node_modules/next/dist/next-server/server/require.js',
2021-02-15T23:25:38.650160+00:00 app[web.1]: '/app/node_modules/next/dist/next-server/server/load-components.js',
2021-02-15T23:25:38.650160+00:00 app[web.1]: '/app/node_modules/next/dist/next-server/server/api-utils.js',
2021-02-15T23:25:38.650160+00:00 app[web.1]: '/app/node_modules/next/dist/next-server/server/next-server.js',
2021-02-15T23:25:38.650160+00:00 app[web.1]: '/app/node_modules/next/dist/server/next.js',
2021-02-15T23:25:38.650160+00:00 app[web.1]: '/app/server.js'
2021-02-15T23:25:38.650161+00:00 app[web.1]: ]
2021-02-15T23:25:38.650161+00:00 app[web.1]: }

I can provide more logs, package.json, etc if needed. Might be related to https://github.com/blitz-js/babel-plugin-superjson-next/pull/39#issuecomment-776962782

Skn0tt commented 3 years ago

That's weird. #39 hasn't been merged yet, and I doubt it's related. Maybe Heroku's npm install just failed ... Does the issue still persist? package.json and package-lock would be very interesting, indeed.

alexfinnarn commented 3 years ago

npm install finishes and it's a Next.js project with npm run build also...I use Yarn but Heroku might switch to npm...but if you're familiar with Heroku, the "build" phase and generated "slug" are fine, it's in the run-time "npm run start" that fails.

I have this repo public, so easy to share...

https://github.com/CUCentralAdvancement/cms/blob/main/package.json https://github.com/CUCentralAdvancement/cms/blob/main/yarn.lock

TSconfig.json might also be in play with the ejs vs common module loading option?

https://github.com/CUCentralAdvancement/cms/blob/main/tsconfig.json

flybayer commented 3 years ago

@alexfinnarn sounds like you need to move babel-plugin-superjson-next from a dev dependency to a regular dependency. 🤔

Skn0tt commented 3 years ago

That should help 👍 @alexfinnarn feel free to re-open if that doesn't help :)

alexfinnarn commented 3 years ago

Thanks, changing that did help!...although I had some other minor code things I needed to update as well for my deployment to not break.

I guess I copied the install command wrong and thought all Babel dependencies go in devDependencies since that's where I have @babel/core. Should I move @babel/core out of a dev dependency?

The issue can remain closed and might help someone else...I just had that follow-up question since I clearly don't know much about using Babel.

flybayer commented 3 years ago

devDependencies vs dependencies is basically a trash situation for apps. They don't really make a difference in most cases. The difference is mainly effective for libraries.