standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 147 forks source link

`esm` fails in a monorepo (turborepo) #923

Closed ihatelactose closed 1 year ago

ihatelactose commented 1 year ago

Description

I have a Hapijs applications which I am trying to refactor into a monorepo however when I try to start the application it fails with a huge log. Tbh it looks like it just outputs the build of esm in my console. At the bottom seems like it was not able to find something that relates to the project?

Logs

If I start with yarn dev which is set to turbo start:development --parallel which starts the two in parallel.

yarn run v1.22.19
$ turbo start:development --parallel
• Packages in scope: consumer, eslint-config-common, reporting
• Running start:development in 3 packages
• Remote caching disabled
consumer:start:development: cache bypass, force executing e7940fa5e88a71ec
reporting:start:development: cache bypass, force executing 25dd7f44111f8151
consumer:start:development: $ export NODE_ENV=development && npx nodemon index.cjs
reporting:start:development: $ export NODE_ENV=development && npx nodemon index.cjs
reporting:start:development: [nodemon] 2.0.20
reporting:start:development: [nodemon] to restart at any time, enter `rs`
reporting:start:development: [nodemon] watching path(s): *.*
reporting:start:development: [nodemon] watching extensions: cjs,json
reporting:start:development: [nodemon] starting `node index.cjs`
consumer:start:development: [nodemon] 2.0.20
consumer:start:development: [nodemon] to restart at any time, enter `rs`
consumer:start:development: [nodemon] watching path(s): *.*
consumer:start:development: [nodemon] watching extensions: cjs,json
consumer:start:development: [nodemon] starting `node index.cjs`
consumer:start:development: /Users/apple/Projects/some-project/node_modules/esm/esm.js:1
consumer:start:development: [nodemon] app crashed - waiting for file changes before starting...
reporting:start:development: /Users/apple/Projects/some-project/node_modules/esm/esm.js:1
reporting:start:development: [nodemon] app crashed - waiting for file changes before starting...

Now the above is not helpful so I went in one of monorepos and tried to manually start one of them!

yarn run v1.22.15
$ export NODE_ENV=development && npx nodemon index.js
[nodemon] 2.0.20
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
/Users/apple/Projects/some-project/node_modules/esm/esm.js:1

/// OUTPUTS GIBBERISH SEEMS LIKE BUILD - See at the bottom

/Users/apple/Projects/some-project/node_modules/hapi-swaggerui/lib/index.js:1
Error: Cannot find module 'hbs'
Require stack:
- /Users/apple/Projects/some-project/node_modules/hapi-swaggerui/lib/index.js
- /Users/apple/Projects/some-project/node_modules/hapi-swaggerui/index.js
- /Users/apple/Projects/some-project/apps/consumer/server.js
- /Users/apple/Projects/some-project/apps/consumer/index.js
    at Object.<anonymous> (/Users/apple/Projects/some-project/node_modules/hapi-swaggerui/lib/index.js:3:13)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/apple/Projects/some-project/node_modules/hapi-swaggerui/lib/index.js',
    '/Users/apple/Projects/some-project/node_modules/hapi-swaggerui/index.js',
    '/Users/apple/Projects/some-project/apps/consumer/server.js',
    '/Users/apple/Projects/some-project/apps/consumer/index.js'
  ]
}
[nodemon] app crashed - waiting for file changes before starting...

If you wanna see the output that is emitted where I've written that it emits the build code here it is PasteBin

Any help is much appreciated on this!

ihatelactose commented 1 year ago

Now if I add hbs its working! It should work even without since hbs is not my requirement! I am closing this since this doesn't look like an issue with esm but rather with module resolution of turborepo.