Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Preview errors: Could not resolve "prettier" and Could not resolve "pg-cloudflare" #263

Open
AlessioGr opened this issue Jan 17, 2025 · 2 comments
Labels
bug Something isn't working triage

Comments

@AlessioGr
Copy link

AlessioGr commented Jan 17, 2025

Describe the bug

I'm getting the following output when running the preview script in my project that uses Payload:

alessio@Alessios-MacBook-Pro cfp % npm run preview

> [email protected] preview
> npm run build:worker && npm run dev:worker


> [email protected] build:worker
> opennextjs-cloudflare


┌─────────────────────────────┐
│ OpenNext — Cloudflare build │
└─────────────────────────────┘

App directory: /Users/alessio/Documents/temp/cfp
Next.js version : 15.1.4
OpenNext v3.3.1

┌─────────────────────────────────┐
│ OpenNext — Building Next.js app │
└─────────────────────────────────┘


> [email protected] build
> cross-env NODE_OPTIONS=--no-deprecation next build

   ▲ Next.js 15.1.4
   - Environments: .env
   - Experiments (use with caution):
     · turbo

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
 ✓ Generating static pages (6/6)
 ✓ Collecting build traces    
 ✓ Finalizing page optimization    

Route (app)                              Size     First Load JS
┌ ○ /_not-found                          990 B           107 kB
├ ƒ /admin/[[...segments]]               346 B           505 kB
├ ƒ /api/[...slug]                       540 B           107 kB
├ ƒ /api/graphql                         518 B           107 kB
├ ƒ /api/graphql-playground              540 B           107 kB
└ ƒ /my-route                            518 B           107 kB
+ First Load JS shared by all            106 kB
  ├ chunks/1517-57809bca0656bc1e.js      50.7 kB
  ├ chunks/4bd1b696-56f2ae1e90601733.js  53 kB
  └ other shared chunks (total)          2.59 kB


○  (Static)   prerendered as static content
ƒ  (Dynamic)  server-rendered on demand


┌──────────────────────────────┐
│ OpenNext — Generating bundle │
└──────────────────────────────┘

Bundling middleware function...
Bundling static assets...
Bundling cache assets...
Building server function: default...
# copyPackageTemplateFiles
⚙️ Bundling the OpenNext server...

# patchWranglerDeps
# updateWebpackChunksFile
 - chunk 1413.js
 - chunk 1427.js
 - chunk 1438.js
 - chunk 1567.js
 - chunk 1679.js
 - chunk 1805.js
 - chunk 1830.js
 - chunk 1879.js
 - chunk 207.js
 - chunk 2220.js
 - chunk 2486.js
 - chunk 2560.js
 - chunk 2584.js
 - chunk 2661.js
 - chunk 3264.js
 - chunk 3287.js
 - chunk 3360.js
 - chunk 3391.js
 - chunk 3455.js
 - chunk 356.js
 - chunk 3607.js
 - chunk 3854.js
 - chunk 4121.js
 - chunk 4583.js
 - chunk 4592.js
 - chunk 4675.js
 - chunk 4915.js
 - chunk 4995.js
 - chunk 5039.js
 - chunk 5051.js
 - chunk 5150.js
 - chunk 517.js
 - chunk 5344.js
 - chunk 5438.js
 - chunk 5555.js
 - chunk 5819.js
 - chunk 6098.js
 - chunk 6194.js
 - chunk 6213.js
 - chunk 635.js
 - chunk 6420.js
 - chunk 6445.js
 - chunk 6551.js
 - chunk 6796.js
 - chunk 681.js
 - chunk 6873.js
 - chunk 7132.js
 - chunk 7135.js
 - chunk 7232.js
 - chunk 7304.js
 - chunk 7305.js
 - chunk 7392.js
 - chunk 7439.js
 - chunk 7490.js
 - chunk 7544.js
 - chunk 7627.js
 - chunk 7730.js
 - chunk 776.js
 - chunk 8003.js
 - chunk 811.js
 - chunk 8112.js
 - chunk 8201.js
 - chunk 8403.js
 - chunk 8526.js
 - chunk 8614.js
 - chunk 8765.js
 - chunk 8881.js
 - chunk 8919.js
 - chunk 9098.js
 - chunk 9329.js
 - chunk 9341.js
 - chunk 9365.js
 - chunk 9584.js
 - chunk 9714.js
 - chunk 9854.js
Applying code patches:
 - patching require
 - patching `buildId` function
 - patching `loadManifest` function
 - patching next's require
 - patching `findDir` function
 - patching `evalManifest` function
 - patching cacheHandler
 - patching 'require(this.middlewareManifestPath)'
 - patching exception bubbling
 - patching `loadInstrumentationModule` function
 - patching `patchAsyncStorage` call
 - patching `eval("require")` calls
 - patching `require.resolve` call
All 13 patches applied

Worker saved in `/Users/alessio/Documents/temp/cfp/.open-next/worker.js` 🚀

OpenNext build complete.

> [email protected] dev:worker
> wrangler dev --port 8771


 ⛅️ wrangler 3.103.1
--------------------

Using vars defined in .dev.vars
Your worker has access to the following bindings:
- Vars:
  - NEXTJS_ENV: "(hidden)"
[wrangler:inf] Ready on http://localhost:8771

✘ [ERROR] Build failed with 6 errors:

  ✘ [ERROR] Could not resolve "prettier"
  
      .open-next/.next/standalone/.next/server/app/(payload)/admin/[[...segments]]/page.js:1:1699:
        1 │ ...e strict";e.exports=import("prettier")},34589:e=>{"use strict";e...
          ╵                               ~~~~~~~~~~
  
    The module "./standalone.mjs" was not found on the file system:
  
      .open-next/.next/standalone/node_modules/prettier/package.json:19:18:
        19 │         "import": "./standalone.mjs",
           ╵                   ~~~~~~~~~~~~~~~~~~
  
    You can mark the path "prettier" as external to exclude it from the bundle, which will remove
  this error. You can also add ".catch()" here to handle this failure at run-time instead of
  bundle-time.
  
  
  ✘ [ERROR] Could not resolve "prettier"
  
      .open-next/.next/standalone/.next/server/app/(payload)/api/[...slug]/route.js:1:1871:
        1 │ ...e strict";e.exports=import("prettier")},34589:e=>{"use strict";e...
          ╵                               ~~~~~~~~~~
  
    The module "./standalone.mjs" was not found on the file system:
  
      .open-next/.next/standalone/node_modules/prettier/package.json:19:18:
        19 │         "import": "./standalone.mjs",
           ╵                   ~~~~~~~~~~~~~~~~~~
  
    You can mark the path "prettier" as external to exclude it from the bundle, which will remove
  this error. You can also add ".catch()" here to handle this failure at run-time instead of
  bundle-time.
  
  
  ✘ [ERROR] Could not resolve "prettier"
  
      .open-next/.next/standalone/.next/server/app/(payload)/api/graphql-playground/route.js:1:1871:
        1 │ ...e strict";e.exports=import("prettier")},34589:e=>{"use strict";e...
          ╵                               ~~~~~~~~~~
  
    The module "./standalone.mjs" was not found on the file system:
  
      .open-next/.next/standalone/node_modules/prettier/package.json:19:18:
        19 │         "import": "./standalone.mjs",
           ╵                   ~~~~~~~~~~~~~~~~~~
  
    You can mark the path "prettier" as external to exclude it from the bundle, which will remove
  this error. You can also add ".catch()" here to handle this failure at run-time instead of
  bundle-time.
  
  
  ✘ [ERROR] Could not resolve "prettier"
  
      .open-next/.next/standalone/.next/server/app/(payload)/api/graphql/route.js:1:1871:
        1 │ ...e strict";e.exports=import("prettier")},34589:e=>{"use strict";e...
          ╵                               ~~~~~~~~~~
  
    The module "./standalone.mjs" was not found on the file system:
  
      .open-next/.next/standalone/node_modules/prettier/package.json:19:18:
        19 │         "import": "./standalone.mjs",
           ╵                   ~~~~~~~~~~~~~~~~~~
  
    You can mark the path "prettier" as external to exclude it from the bundle, which will remove
  this error. You can also add ".catch()" here to handle this failure at run-time instead of
  bundle-time.
  
  
  ✘ [ERROR] Could not resolve "prettier"
  
      .open-next/.next/standalone/.next/server/app/my-route/route.js:1:1586:
        1 │ ...e strict";e.exports=import("prettier")},34589:e=>{"use strict";e...
          ╵                               ~~~~~~~~~~
  
    The module "./standalone.mjs" was not found on the file system:
  
      .open-next/.next/standalone/node_modules/prettier/package.json:19:18:
        19 │         "import": "./standalone.mjs",
           ╵                   ~~~~~~~~~~~~~~~~~~
  
    You can mark the path "prettier" as external to exclude it from the bundle, which will remove
  this error. You can also add ".catch()" here to handle this failure at run-time instead of
  bundle-time.
  
  
  ✘ [ERROR] Could not resolve "pg-cloudflare"
  
      .open-next/.next/standalone/node_modules/pg/lib/stream.js:10:41:
        10 │     const { CloudflareSocket } = require('pg-cloudflare')
           ╵                                          ~~~~~~~~~~~~~~~
  
    The module "./dist/index.js" was not found on the file system:
  
      .open-next/.next/standalone/node_modules/pg-cloudflare/package.json:13:15:
        13 │     "workerd": "./dist/index.js",
           ╵                ~~~~~~~~~~~~~~~~~
  
    You can mark the path "pg-cloudflare" as external to exclude it from the bundle, which will
  remove this error. You can also surround this "require" call with a try/catch block to handle this
  failure at run-time instead of bundle-time.
  
  


🪵  Logs were written to "/Users/alessio/Library/Preferences/.wrangler/logs/wrangler-2025-01-17_05-00-53_570.log"
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
│  [b] open a browser, [d] open devtools, [l] turn off local mode, [c] clear console, [x] to exit  │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
alessio@Alessios-MacBook-Pro cfp % 

The prettier error specifically is caused by the following line that is part of Payload: https://github.com/payloadcms/payload/blob/v3.17.1/packages/drizzle/src/utilities/createSchemaGenerator.ts#L296

Is importing prettier like that not supported? This line would never execute - it works fine outside of opennext.

As for pg, is the pg package supported?

Steps to reproduce

  1. Clone https://github.com/AlessioGr/opennext-cloudflare-bug
  2. Copy .env.example to .env
  3. Run npm install
  4. Ensure you have postgres installed locally. Make sure the POSTGRES_URL url in your .env file is correct.
  5. Run npm run preview

Expected behavior

Preview command does not fail

@opennextjs/cloudflare version

0.3.8

Wrangler version

3.103.1

next info output

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.2.0: Fri Dec  6 19:02:12 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6031
  Available memory (MB): 65536
  Available CPU cores: 16
Binaries:
  Node: 23.3.0
  npm: 10.9.0
  Yarn: 1.22.22
  pnpm: 9.15.4
Relevant Packages:
  next: 15.1.4 // Latest available version is detected (15.1.4).
  eslint-config-next: 15.1.4
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.2
Next.js Config:
  output: N/A

Additional context

Installing prettier and pg-cloudflare as a dependency made no difference

@AlessioGr AlessioGr added bug Something isn't working triage labels Jan 17, 2025
@r1tsuu
Copy link

r1tsuu commented Jan 17, 2025

Also, manually removing prettier imports from the output files allows to go a bit further, but the database connection fails. In all our 3 adapters, PG, SQLite and MongoDB.

For example, with MongoDB it says net is not implemented yet!

Image

Also, it seems like the pino logger doesn't work. Replacing with console works.

@vicb
Copy link
Contributor

vicb commented Jan 17, 2025

net has been implemented by @anonrig and mongoDB has been tested successfully. This should be available soon (1-2 weeks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Development

No branches or pull requests

3 participants