Module parse failed: Unexpected token (1:7)

Hello, there is an issue when I try to deploy my repository. For environmental variables I have CI = true. I’m using yarn to install the modules and there is a yarn.lock. My next config only contains reactStrictMode: true.

Build:

6:34:16 PM: $ yarn build
6:34:16 PM: yarn run v1.22.10
6:34:16 PM: $ next build
6:34:17 PM: info - Using webpack 5. Reason: Enabled by default webpack5 | Next.js
6:34:18 PM: info - Checking validity of types…
6:34:21 PM: info - Creating an optimized production build…
6:34:56 PM: (node:1481) [DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE] DeprecationWarning: Chunk.hasEntryModule: Use new ChunkGraph API
6:34:59 PM: Failed to compile.
6:34:59 PM:
6:34:59 PM: ./node_modules/esbuild/lib/main.d.ts
6:34:59 PM: Module parse failed: Unexpected token (1:7)
6:34:59 PM: You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See Concepts | webpack
6:34:59 PM: > export type Platform = ‘browser’ | ‘node’ | ‘neutral’;
6:34:59 PM: | export type Format = ‘iife’ | ‘cjs’ | ‘esm’;
6:34:59 PM: | export type Loader = ‘js’ | ‘jsx’ | ‘ts’ | ‘tsx’ | ‘css’ | ‘json’ | ‘text’ | ‘base64’ | ‘file’ | ‘dataurl’ | ‘binary’ | ‘default’;
6:34:59 PM: > Build error occurred
6:34:59 PM: Error: > Build failed because of webpack errors
6:34:59 PM: at /opt/build/repo/node_modules/next/dist/build/index.js:397:19
6:34:59 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:60:20)
6:34:59 PM: at async Object.build [as default] (/opt/build/repo/node_modules/next/dist/build/index.js:77:25)
6:34:59 PM: error Command failed with exit code 1.
6:34:59 PM: info Visit yarn run | Yarn for documentation about this command.
6:34:59 PM: ​
6:34:59 PM: ────────────────────────────────────────────────────────────────
6:34:59 PM: “build.command” failed
6:34:59 PM: ────────────────────────────────────────────────────────────────
6:34:59 PM: ​
6:34:59 PM: Error message
6:34:59 PM: Command failed with exit code 1: yarn build
6:34:59 PM: ​
6:34:59 PM: Error location
6:34:59 PM: In Build command from Netlify app:
6:34:59 PM: yarn build
6:34:59 PM: ​
6:34:59 PM: Resolved config
6:34:59 PM: build:
6:34:59 PM: command: yarn build
6:34:59 PM: commandOrigin: ui
6:34:59 PM: environment:
6:34:59 PM: - CI
6:34:59 PM: publish: /opt/build/repo/build
6:34:59 PM: publishOrigin: ui
6:34:59 PM: plugins:
6:34:59 PM: - inputs: {}
6:34:59 PM: origin: ui
6:34:59 PM: package: ‘@netlify/plugin-nextjs’
6:35:00 PM: Caching artifacts
6:35:00 PM: Started saving node modules
6:35:00 PM: Finished saving node modules
6:35:00 PM: Started saving build plugins
6:35:00 PM: Finished saving build plugins
6:35:00 PM: Started saving yarn cache
6:35:10 PM: Finished saving yarn cache
6:35:10 PM: Started saving pip cache
6:35:10 PM: Finished saving pip cache
6:35:10 PM: Started saving emacs cask dependencies
6:35:10 PM: Finished saving emacs cask dependencies
6:35:10 PM: Started saving maven dependencies
6:35:10 PM: Finished saving maven dependencies
6:35:10 PM: Started saving boot dependencies
6:35:10 PM: Finished saving boot dependencies
6:35:10 PM: Started saving rust rustup cache
6:35:10 PM: Finished saving rust rustup cache
6:35:10 PM: Started saving go dependencies
6:35:10 PM: Finished saving go dependencies
6:35:10 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
6:35:10 PM: Creating deploy upload records
6:35:10 PM: Failing build: Failed to build site
6:35:10 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
6:35:10 PM: Finished processing build request in 1m56.71382048s

hi there, does this build locally? given that this is a compile error of sorts, i would expect it to fail locally as well. is this the case? if yes, then you’ll need to figure out what exactly is happening in that file at the line indicated that is causing the error. if not, as in, it works locally, let us know and we can do some more debugging.

Hello, it does build locally.

This is the build locally.
info - Using webpack 5. Reason: Enabled by default webpack5 | Next.js
info - Checking validity of types
info - Creating an optimized production build
info - Compiled successfully
info - Collecting page data
info - Generating static pages (6/6)
info - Finalizing page optimization

Page Size First Load JS
┌ ○ / 3.57 kB 96.8 kB
├ └ css/f98efd321a42423ca885.css 1.05 kB
├ /_app 0 B 93.2 kB
├ ○ /404 504 B 93.7 kB
├ └ css/881f86d44688e54d0764.css 289 B
├ ● /posts (593 ms) 1.67 kB 102 kB
├ └ css/1c1bf45b9cff12d192c6.css 733 B
├ ● /posts/[slug] (742 ms) 45.4 kB 146 kB
├ └ css/73791fb9c4104ee62b34.css 423 B
├ └ /posts/install-neovim (742 ms)
└ ○ /projects 2.71 kB 95.9 kB
└ css/e651a8a8816e2a8e523d.css 661 B

  • First Load JS shared by all 93.2 kB
    ├ chunks/framework.2191d1.js 42.4 kB
    ├ chunks/main.c4f254.js 23.6 kB
    ├ chunks/pages/_app.633a38.js 26.3 kB
    ├ chunks/webpack.0e3c27.js 883 B
    └ css/cb37bcc4829bf3036095.css 1.74 kB

λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
○ (Static) automatically rendered as static HTML (uses no initial props)
● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)
(ISR) incremental static regeneration (uses revalidate in getStaticProps)

I found the solution, I had to downgrade next-mdx-remote to @3.0.5 and I had to install @babel/core as a dev dependency.