While building all errors are sent through a JSON Parser even when they are not JSON in NX 18 with next,
Current Behavior
Failing builds error out without any reporting of what caused the failure
Expected Behavior
It should display the errors and not throw an error attempting to parse them. I downgraded to NX 17 and everything works as expected.
GitHub Repo
No response
Steps to Reproduce
- Have a NX monorepo with an nx/next app
- Have a bug like a type error or scss error
- Attempt to build
Nx Report
NX Report complete - copy this into the issue template
Node : 20.11.1
OS : win32-x64
npm : 8.19.3
nx (global) : 16.3.2
nx : 18.0.8
@nx/js : 18.0.8
@nx/jest : 18.0.8
@nx/linter : 18.0.8
@nx/eslint : 18.0.8
@nx/workspace : 18.0.8
@nx/devkit : 18.0.8
@nx/eslint-plugin : 18.0.8
@nx/next : 18.0.8
@nx/react : 18.0.8
@nrwl/tao : 18.0.8
@nx/web : 18.0.8
typescript : 5.3.3
Failure Logs
> nx run site:build:production
▲ Next.js 14.1.3
Skipping linting
✓ Checking validity of types
Creating an optimized production build ...
undefined:1
<w> [webpack.cache.PackFileCacheStrategy] Skipped not serializable cache item 'Compilation/modules|C:\xxx\node_modules\next\dist\build\webpack\loaders\css-loader\src\index.js??ruleSet[1].rules[6].oneOf[9].u
se[0]!C:\xxx\node_modules\next\dist\build\webpack\loaders\postcss-loader\src\index.j
s??ruleSet[1].rules[6].oneOf[9].use[1]!C:\Users\karti\Documents\dots\dots\frontends\node_modules\next\dist\build\webpack\l
oaders\resolve-url-loader\index.js??ruleSet[1].rules[6].oneOf[9].use[2]!C:\xxx\node_
modules\next\dist\compiled\sass-loader\cjs.js??ruleSet[1].rules[6].oneOf[9].use[3]!C:\xxx\apps\site\components\text-hero\text-hero.module.scss': No serializer registered for Warning
^
SyntaxError: Unexpected token '<', "<w> [webpa"... is not valid JSON
at parse (<anonymous>)
at parseChannelMessages (node:internal/child_process/serialization:152:15)
at parseChannelMessages.next (<anonymous>)
at channel.onread (node:internal/child_process:624:18)
Node.js v20.11.1
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
NX Ran target build for project site (24s)
× 1/1 failed
√ 0/1 succeeded [0 read from cache]
### Package Manager Version
_No response_
### Operating System
- [X] macOS
- [ ] Linux
- [X] Windows
- [ ] Other (Please specify)
### Additional Information
_No response_
Seeing this as well. 18.0.7 was fine so suspect it's very recently introduced.
Also experienced the issue, reverted back to 18.0.7 and that seems to work.
It looks like this is related https://github.com/nrwl/nx/pull/22190/files#diff-fcd96d0c9996c7987e1c72da9391cb2d845b36ab056886d02511dea284371c5dR140
I have the same issue, works with 18.0.7 but not with 18.0.8. (Linux)
I see this with all patch versions 18.0.0..18.0.8 (downgraded one at a time from 18.0.8):
✓ Creating an optimized production build
✓ Compiled successfully
Skipping linting
Checking validity of types ..undefined:1
Failed to compile.
^
SyntaxError: Unexpected token 'Faile"... is not valid JSON
at parse (<anonymous>)
at parseChannelMessages (node:internal/child_process/serialization:152:15)
at parseChannelMessages.next (<anonymous>)
at channel.onread (node:internal/child_process:624:18)
FYI: In my case, I could resolve the given error by transitioning my project to Inferred Tasks, a feature introduced in Nx 18. Details can be found at this link: https://github.com/nrwl/nx/issues/22295
The first step requires removing the "targets.build" field from your project.json file in your nextjs application.
@@ -1,24 +1,9 @@
{
"name": "myapp",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/myapp",
"projectType": "application",
"targets": {
- "build": {
- "executor": "@nx/next:build",
- "outputs": ["{options.outputPath}"],
- "options": {
- "outputPath": "dist/apps/myapp"
- },
- "configurations": {
- "production": {
- },
- "development": {
- "outputPath": "apps/myapp"
- }
- },
- "defaultConfiguration": "production"
- }
},
"tags": []
}
Following this, a new configuration must be added to nx.json.
@@ -1,27 +1,36 @@
{
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"namedInputs": {
"default": ["{projectRoot}/**/*", "sharedGlobals"],
"production": [
"default",
"!{projectRoot}/.eslintrc.json",
"!{projectRoot}/eslint.config.js",
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/jest.config.[jt]s",
"!{projectRoot}/src/test-setup.[jt]s",
"!{projectRoot}/test-setup.[jt]s"
],
"sharedGlobals": []
},
"plugins": [
+ {
+ "plugin": "@nx/next/plugin",
+ "options": {
+ "buildTargetName": "build",
+ "devTargetName": "dev",
+ "startTargetName": "start",
+ "serveStaticTargetName": "serve-static"
+ }
+ }
],
"generators": {
"@nx/next": {
"application": {
"style": "css",
"linter": "eslint"
}
}
}
}
This should mitigate the error in question.
FYI: In my case, I could resolve the given error by transitioning my project to Inferred Tasks, a feature introduced in Nx 18. Details can be found at this link: #22295
Yes, but how to customize the build options with inferred tasks? for example the outputPath.
the documentation of this feature is poor.
I see this with all patch versions 18.0.0..18.0.8 (downgraded one at a time from 18.0.8):
✓ Creating an optimized production build ✓ Compiled successfully Skipping linting Checking validity of types ..undefined:1 Failed to compile. ^ SyntaxError: Unexpected token 'Faile"... is not valid JSON at parse (<anonymous>) at parseChannelMessages (node:internal/child_process/serialization:152:15) at parseChannelMessages.next (<anonymous>) at channel.onread (node:internal/child_process:624:18)
@v-karbovnichy,
Initially I thought the same, but then I realized that downgrading from 18.0.7 via nx migrate 18.0.7 was only updating the the nx package not @nx/next package where this issue exists. When I explicitly set all @nx/* packages in my repo to 18.0.7 I no longer encounter
SyntaxError: Unexpected token '(', "(node:7487"... is not valid JSON
at parse (<anonymous>)
at parseChannelMessages (node:internal/child_process/serialization:152:15)
at parseChannelMessages.next (<anonymous>)
at channel.onread (node:internal/child_process:624:18)
So an issue in 18.0.8, but not 18.0.7
Looks like the issue got fixed in 18.1.1.
seems like this is still happening in 18.3.4:
npx nx build ****
> nx run ****
▲ Next.js 14.1.3
Creating an optimized production build ...
undefined:1
(node:64148) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
^
SyntaxError: Unexpected token '(', "(node:6414"... is not valid JSON
at parse (<anonymous>)
at parseChannelMessages (node:internal/child_process/serialization:152:15)
at parseChannelMessages.next (<anonymous>)
at channel.onread (node:internal/child_process:624:18)
Node.js v21.5.0
update
Though, I can confirm, removing the "build" from "targets" in project.json does solve the problem, but that's not entirely what I want.
This should be addressed with 18.1.1 @zilahir can you create a new issue with a small reproduction?
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.