kentcdodds / mdx-bundler

🦤 Give me MDX/TSX strings and I'll give you back a component you can render. Supports imports!
MIT License
1.78k stars 75 forks source link

Remix builds not working as soon as I add mdx-bundler #193

Closed ksorv closed 2 years ago

ksorv commented 2 years ago

Relevant code or config

What you did: Just installed the package and used it. Everything works just fine locally but while deploying to fly or railway the build always fails saying:

> PORT=3000 remix-serve build
Error: Cannot find module 'remark-mdx-frontmatter'
Require stack:
- /myapp/build/index.js
- /myapp/node_modules/@remix-run/serve/dist/cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Function.Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at node_modules/mdx-bundler/dist/index.js (/myapp/build/index.js:83:172)
at /myapp/build/index.js:7:50
at Object.<anonymous> (/myapp/build/index.js:1031:34)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)

What happened: Can not get my server to deploy.

Reproduction repository: https://github.com/ksorv/blog

Problem description:

Suggested solution: No idea tried everything that I could find related to the problem.

ksorv commented 2 years ago

@kentcdodds Sorry if the issue doesn't belong here. Please help

kentcdodds commented 2 years ago

I'm not sure what's going on here and I'm afraid I don't have the time to look into this for you :( Hopefully someone else can help!

ksorv commented 2 years ago

Hmm, I hope someone can tag along to help @kentcdodds.

I've been searching for it over n over but found nothing like this one.

Do you maybe have time to give some pointers on where to start debugging I wanna look into it.

ksorv commented 2 years ago

@kentcdodds I think i was able to fix it by using:

function fixEsbuildBinaryError() {
  if (process.platform === 'win32') {
    process.env.ESBUILD_BINARY_PATH = path.join(
      process.cwd(),
      'node_modules',
      'esbuild',
      'esbuild.exe',
    )
  } else {
    process.env.ESBUILD_BINARY_PATH = path.join(
      process.cwd(),
      'node_modules',
      'esbuild',
      'bin',
      'esbuild',
    )
  }
}

fixEsbuildBinaryError();

in the whatever.server.ts file in which i was using mdx-bundler.

So, Closing this one. Thanks for your time.