ricokahler / next-plugin-preval

Pre-evaluate async functions during builds and import them like JSON
MIT License
257 stars 13 forks source link

Stack trace is not propagated on error #22

Closed ricokahler closed 3 years ago

ricokahler commented 3 years ago

It can be pretty frustrating if a preval function throws because the current implementation does not propagate its value. This is a TODO item for myself to fix that.

Vadorequest commented 3 years ago

I don't know if this is related, but while merging a PR I accidently missed on dependency in the package.json. Instead of the usual straightforward error, I got the following stack trace:

<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: ENOENT: no such file or directory, lstat '/Users/vadorequest/dev/TFP-v4/src/modules/core/airtable/fetchRawAirtableDataset.preval.ts.preval-run.js'
<w> [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Resolving '../../../src/modules/core/airtable/fetchRawAirtableDataset.preval.ts.preval-run' in /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/dist for build dependencies doesn't lead to expected result '/Users/vadorequest/dev/TFP-v4/src/modules/core/airtable/fetchRawAirtableDataset.preval.ts.preval-run.js', but to 'Error: Can't resolve '../../../src/modules/core/airtable/fetchRawAirtableDataset.preval.ts.preval-run' in '/Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/dist'' instead. Resolving dependencies are ignored for this path.
<w>  at resolve commonjs file ../../../src/modules/core/airtable/fetchRawAirtableDataset.preval.ts.preval-run (expected /Users/vadorequest/dev/TFP-v4/src/modules/core/airtable/fetchRawAirtableDataset.preval.ts.preval-run.js)
<w>  at file dependencies /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/dist/loader.js
<w>  at file /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/dist/loader.js
<w>  at file dependencies /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/loader.js
<w>  at file /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/loader.js
<w>  at resolve commonjs /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/loader.js
error - ./src/modules/core/airtable/fetchRawAirtableDataset.preval.ts
Error: Failed to pre-evaluate "/Users/vadorequest/dev/TFP-v4/src/modules/core/airtable/fetchRawAirtableDataset.preval.ts". Error: Cannot find module '@unly/simple-logger'
Require stack:
- /Users/vadorequest/dev/TFP-v4/src/modules/core/logging/logger.ts
- /Users/vadorequest/dev/TFP-v4/src/modules/core/airtable/fetchRawAirtableDataset.ts
- /Users/vadorequest/dev/TFP-v4/src/modules/core/airtable/fetchRawAirtableDataset.preval.ts.preval-run.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/dist/loader.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/loader.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/compiled/webpack/bundle5.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/compiled/webpack/webpack.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/config-utils-worker.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/config-utils.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/config.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/server/next.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/server/lib/start-server.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/cli/next-dev.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/bin/next
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: ENOENT: no such file or directory, lstat '/Users/vadorequest/dev/TFP-v4/src/modules/core/i18n/fetchLocizeTranslations.preval.ts.preval-run.js'
<w> [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Resolving '../../../src/modules/core/i18n/fetchLocizeTranslations.preval.ts.preval-run' in /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/dist for build dependencies doesn't lead to expected result '/Users/vadorequest/dev/TFP-v4/src/modules/core/i18n/fetchLocizeTranslations.preval.ts.preval-run.js', but to 'Error: Can't resolve '../../../src/modules/core/i18n/fetchLocizeTranslations.preval.ts.preval-run' in '/Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/dist'' instead. Resolving dependencies are ignored for this path.
<w>  at resolve commonjs file ../../../src/modules/core/i18n/fetchLocizeTranslations.preval.ts.preval-run (expected /Users/vadorequest/dev/TFP-v4/src/modules/core/i18n/fetchLocizeTranslations.preval.ts.preval-run.js)
<w>  at file dependencies /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/dist/loader.js
<w>  at file /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/dist/loader.js
<w>  at file dependencies /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/loader.js
<w>  at file /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/loader.js
<w>  at resolve commonjs /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/loader.js
event - build page: /api/autoRedirectToLocalisedPage
wait  - compiling...
error - ./src/modules/core/airtable/fetchRawAirtableDataset.preval.ts
Error: Failed to pre-evaluate "/Users/vadorequest/dev/TFP-v4/src/modules/core/airtable/fetchRawAirtableDataset.preval.ts". Error: Cannot find module '@unly/simple-logger'
Require stack:
- /Users/vadorequest/dev/TFP-v4/src/modules/core/logging/logger.ts
- /Users/vadorequest/dev/TFP-v4/src/modules/core/airtable/fetchRawAirtableDataset.ts
- /Users/vadorequest/dev/TFP-v4/src/modules/core/airtable/fetchRawAirtableDataset.preval.ts.preval-run.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/dist/loader.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next-plugin-preval/loader.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/compiled/webpack/bundle5.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/compiled/webpack/webpack.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/config-utils-worker.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/config-utils.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/config.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/server/next.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/server/lib/start-server.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/cli/next-dev.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/bin/next
Error: Cannot find module '/Users/vadorequest/dev/TFP-v4/.next/server/pages-manifest.json'
Require stack:
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/require.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/load-components.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/api-utils.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/next-server.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/server/next.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/server/lib/start-server.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/cli/next-dev.js
- /Users/vadorequest/dev/TFP-v4/node_modules/next/dist/bin/next
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.mod._resolveFilename (/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/build/webpack/require-hook.js:4:1784)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at getPagePath (/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/require.js:1:735)
    at DevServer.getPagePath (/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/next-server.js:58:1364)
    at DevServer.handleApiRequest (/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/next-server.js:66:79)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async Object.fn (/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/next-server.js:58:580)
    at async applyCheckTrue (/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/router.js:5:179)
    at async Router.execute (/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/router.js:29:31)
    at async DevServer.run (/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/next-server.js:68:1042)
    at async DevServer.handleRequest (/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/next-server.js:32:504) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/require.js',
    '/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/load-components.js',
    '/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/api-utils.js',
    '/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/next-server/server/next-server.js',
    '/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/server/next.js',
    '/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/server/lib/start-server.js',
    '/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/cli/next-dev.js',
    '/Users/vadorequest/dev/TFP-v4/node_modules/next/dist/bin/next'
  ]
}

Somewhere there, you can see Error: Cannot find module '@unly/simple-logger' which was my mistake, but hardly visible. (spent 30mn trying various fixes, focused on Error: Can't resolve '../../../src/modules/core/airtable/fetchRawAirtableDataset.preval.ts.preval-run error instead.

ricokahler commented 3 years ago

This one definitely seems like the most annoying to deal with so I'm currently prioritizing it. I should have something out soon!

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 1.1.0-alpha.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

ricokahler commented 3 years ago

~This alpha release is kind of buggy. Seems like using babel register doesn't compile the right files all the time. I'll address soon~

nvm i figured it out. I'll release soon after some more testing

ricokahler commented 3 years ago

released in 1.1.0 😄

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 1.2.0-alpha.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: