payloadcms / next-payload

A utility to deploy Payload serverlessly within a Next.js app
308 stars 44 forks source link

Module parse failed error when bundling sharp-darwin-arm64v8.node #65

Closed thompsonsj closed 5 months ago

thompsonsj commented 1 year ago

When payloadcms/next-payload detects that sharp should be bundled, npm run dev fails.

I see a similar issue in https://github.com/payloadcms/next-payload/issues/48 and this was resolved. My install is new with the latest version of all packages.

Could this be because I am on the M2 chip? I have no idea where to start 😅 .

- wait compiling /api/[collection]/init (client and server)...
- wait compiling /api/[collection]/me (client and server)...
- error ./node_modules/payload/node_modules/sharp/build/Release/sharp-darwin-arm64v8.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
Import trace for requested module:
./node_modules/payload/node_modules/sharp/build/Release/sharp-darwin-arm64v8.node
./node_modules/payload/node_modules/sharp/build/Release/ sync ^\.\/sharp\-.*\.node$
./node_modules/payload/node_modules/sharp/lib/sharp.js
./node_modules/payload/node_modules/sharp/lib/constructor.js
./node_modules/payload/node_modules/sharp/lib/index.js
./node_modules/payload/dist/uploads/generateFileData.js
./node_modules/payload/dist/collections/operations/create.js
./node_modules/payload/dist/collections/operations/local/create.js
./node_modules/payload/dist/collections/operations/local/index.js
./node_modules/payload/dist/payload.js
./src/payload/payloadClient.ts
./node_modules/@payloadcms/next-payload/dist/middleware/withPayload.js
./node_modules/@payloadcms/next-payload/dist/handlers/[collection]/init.js
./src/pages/api/[collection]/init.ts

Have tried including node-loader but this yields more errors.

{
// ...
admin: {
  webpack: (config) => ({
    ...config,
    module: {
      rules: [
        ...config.module?.rules || [],  
        { test: /\.node$/, use: "node-loader"}
      ]
    }
  })
}
// ...
}
JarrodMFlesch commented 11 months ago

@thompsonsj are you still seeing this error? I am now on M2 but am unable to recreate. Let me know if you have time to test it again, thanks!

timoconnellaus commented 10 months ago

I'm getting this error with an M1 mac @JarrodMFlesch

timoconnellaus commented 10 months ago

I have a workaround working. I installed sharp@0.33.0-alpha.6

jacobsfletch commented 5 months ago

Hey there @thompsonsj and @timoconnellaus, this repo will soon be archived because it's been merged into the main Payload repo here: https://github.com/payloadcms/payload/tree/main/packages/next. Payload 3.0 ships with native support for Next.js and is currently out in beta here: https://github.com/payloadcms/payload-3.0-demo. I'm going to close this issue now but feel free to keep the conversation going either as a GitHub Discussion or on Discord. If think issue persists, feel free to open a new ticket on either the demo repo or the monorepo with the 3.x-beta label, and be sure to include a reproduction so we can fix it faster.