Tao
Tao

Fix oxc-parser Module Error When Deploying Nuxt3 to Cloudflare

I recently ran into a “Cannot find module ‘@oxc-parser/binding-linux-arm64-gnu’” error when deploying my Nuxt3 app to Cloudflare Pages. The build failed during the nuxt prepare step because it couldn’t find the Linux binary files for the oxc-parser module.

This error only happened in Cloudflare’s Linux build environment, not on my local development machine. The strange part was that my previous deployments to Cloudflare Pages worked fine, and I hadn’t changed my package.json file.

Here’s the specific error that showed up during the build:

shell

Error: Cannot find module './parser.linux-x64-gnu.node'

The full build log showed more details about the error:

shell

16:32:49.839	> postinstall
16:32:49.839	> nuxt prepare
16:32:49.839	
16:32:50.685	[error] Failed to load native binding
16:32:50.686	  at Object.<anonymous> (node_modules/oxc-parser/bindings.js:380:11)
16:32:50.686	  at Module._compile (node:internal/modules/cjs/loader:1256:14)
16:32:50.686	  at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
16:32:50.686	  at Module.load (node:internal/modules/cjs/loader:1119:32)
16:32:50.686	  at Module._load (node:internal/modules/cjs/loader:960:12)
16:32:50.687	  at Module.require (node:internal/modules/cjs/loader:1143:19)
16:32:50.687	  at require (node:internal/modules/cjs/helpers:121:18)
16:32:50.687	  at Object.<anonymous> (node_modules/oxc-parser/index.js:3:18)
16:32:50.687	  at Module._compile (node:internal/modules/cjs/loader:1256:14)
16:32:50.687	  at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
16:32:50.687	
16:32:50.687	  [cause]: [ { Error: Cannot find module './parser.linux-x64-gnu.node'
16:32:50.688	  Require stack:
16:32:50.688	  - /opt/buildhome/repo/node_modules/oxc-parser/bindings.js
16:32:50.688	      at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
16:32:50.688	      at Module._load (node:internal/modules/cjs/loader:922:27)
16:32:50.688	      at Module.require (node:internal/modules/cjs/loader:1143:19)
16:32:50.688	      at require (node:internal/modules/cjs/helpers:121:18)
16:32:50.688	      at requireNative (/opt/buildhome/repo/node_modules/oxc-parser/bindings.js:224:16)
16:32:50.688	      at Object.<anonymous> (/opt/buildhome/repo/node_modules/oxc-parser/bindings.js:345:17)
16:32:50.688	      at Module._compile (node:internal/modules/cjs/loader:1256:14)
16:32:50.689	      at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
16:32:50.689	      at Module.load (node:internal/modules/cjs/loader:1119:32)
16:32:50.689	      at Module._load (node:internal/modules/cjs/loader:960:12)
16:32:50.689	    code: 'MODULE_NOT_FOUND',
16:32:50.689	    requireStack: [ '/opt/buildhome/repo/node_modules/oxc-parser/bindings.js' ] },
16:32:50.689	  { Error: Cannot find module '@oxc-parser/binding-linux-x64-gnu'
16:32:50.689	  Require stack:
16:32:50.689	  - /opt/buildhome/repo/node_modules/oxc-parser/bindings.js
16:32:50.689	      at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
16:32:50.690	      at Module._load (node:internal/modules/cjs/loader:922:27)
16:32:50.690	      at Module.require (node:internal/modules/cjs/loader:1143:19)
16:32:50.690	      at require (node:internal/modules/cjs/helpers:121:18)
16:32:50.690	      at requireNative (/opt/buildhome/repo/node_modules/oxc-parser/bindings.js:229:16)
16:32:50.690	      at Object.<anonymous> (/opt/buildhome/repo/node_modules/oxc-parser/bindings.js:345:17)
16:32:50.690	      at Module._compile (node:internal/modules/cjs/loader:1256:14)
16:32:50.690	      at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
16:32:50.691	      at Module.load (node:internal/modules/cjs/loader:1119:32)
16:32:50.691	      at Module._load (node:internal/modules/cjs/loader:960:12)
16:32:50.691	    code: 'MODULE_NOT_FOUND',
16:32:50.691	    requireStack: [ '/opt/buildhome/repo/node_modules/oxc-parser/bindings.js' ] } ]

The error points to an issue with the oxc-parser package. This package is a JavaScript parser that uses native Rust modules for high-performance parsing.

The main problems are:

  1. Can’t find the ./parser.linux-x64-gnu.node file
  2. Can’t find the @oxc-parser/binding-linux-x64-gnu module

This means the oxc-parser package doesn’t have pre-built binary files for the Linux x64 architecture in the current version. Cloudflare Pages runs on Linux x64 platforms.

While searching for similar issues, I found a related GitHub issue in the Nuxt repository: https://github.com/nuxt/nuxt/issues/31954

From this issue, I learned that:

  • This is a known problem affecting specific combinations of Node.js versions and oxc-parser
  • The root cause is that oxc-parser doesn’t provide Linux binary files for certain Node.js versions
  • The solution is to upgrade to Node.js version 20.9.0 or higher
  • First, I needed to check which Node.js version Cloudflare Pages was using. I found that the default Cloudflare v2 build system uses Node.js version 18.17.1

  • I checked if there was a .nvmrc file in the project root. My project didn’t have one.

I realized I needed to upgrade the project to Node.js 20.9 or higher.

Based on the GitHub issue recommendation, I needed to upgrade to a newer Node.js version. I recommend using Node.js 20.9 or higher.

In Cloudflare Pages, you can specify the Node.js version in these ways:

Method 1: Create a .nvmrc file

shell

22.16.0

Method 2: Set Environment Variable In Cloudflare Pages settings, add this environment variable:

  • Variable name: NODE_VERSION
  • Value: 22.16.0

After upgrading the Node.js version, trigger a new build and deployment. The new build process should be able to find the correct binary files.

After upgrading Node.js, the next deployment should show successful build logs. The nuxt prepare command should complete normally without any oxc-parser related errors.

The solution for this problem is simple, but figuring it out can take time. The root cause is platform compatibility issues with the oxc-parser native module.

By upgrading the Node.js version, we successfully fixed the oxc-parser module error when deploying Nuxt3 to Cloudflare. This case reminds us to pay attention to platform compatibility and Node.js version requirements when using JavaScript packages with native modules.

Related Content