nx
nx copied to clipboard
Build nextJS app issue - Cannot read properties of null (reading 'message')
Current Behavior
When i build locally app, usign nx run web:build
all works fine. But when I build docker image anr run RUN npx nx run web:build
a got a misleading error:
332.1 ƒ Middleware 40.3 kB
332.1
332.1 ○ (Static) prerendered as static content
332.1 λ (Dynamic) server-rendered on demand using Node.js
332.1
332.8
332.8
332.8
332.8 NX Successfully ran target build for project web and 2 tasks it depends on
332.8
332.8
332.8
332.8 NX Cannot read properties of null (reading 'message')
332.8
332.8 Pass --verbose to see the stacktrace.
332.8
------
failed to solve: process "/bin/sh -c npx nx run web:build ${BUILD_FLAG}" did not complete successfully: exit code: 1
So I see that NextJS app was built, but the error broke my image build
Expected Behavior
No error durning docker build
GitHub Repo
No response
Steps to Reproduce
- create docker image and build it
Nx Report
Node : 20.11.1
OS : darwin-arm64
pnpm : 8.15.2
nx (global) : 18.3.4
nx : 18.3.4
@nx/js : 18.3.4
@nx/jest : 18.3.4
@nx/eslint : 18.3.4
@nx/workspace : 18.3.4
@nx/cypress : 18.3.4
@nx/esbuild : 18.3.4
@nx/eslint-plugin : 18.3.4
@nx/nest : 18.3.4
@nx/next : 18.3.4
@nx/node : 18.3.4
@nx/react : 18.3.4
@nrwl/tao : 18.3.4
@nx/web : 18.3.4
@nx/webpack : 18.3.4
typescript : 5.4.5
---------------------------------------
Registered Plugins:
@nx/next/plugin
@nx/cypress/plugin
@nx/eslint/plugin
@nx/jest/plugin
@nx/webpack/plugin
Failure Logs
No response
Package Manager Version
pnpm 8.15.2
Operating System
- [X] macOS
- [ ] Linux
- [ ] Windows
- [ ] Other (Please specify)
Additional Information
Here is my docker file:
FROM linkerry-base:base AS builder
ARG NODE_ENV
ARG BUILD_FLAG
WORKDIR /app/builder
# comment this step now, project files alreaady exists
# COPY . .
RUN npx nx run web:build ${BUILD_FLAG}
FROM linkerry-base:base
WORKDIR /app
COPY --from=builder /app/builder ./
ENV NODE_ENV=$NODE_ENV
CMD ["nx", "run", "web:start"]
This issue also occurs when u build docker image for my nestJS app
I had this issue when migrating to a newer version of NX (unsure if related) and found that force disabling the NX Daemon in my Dockerfile solved my issue: ENV NX_DAEMON=false
- https://nx.dev/concepts/more-concepts/nx-daemon
- https://github.com/nrwl/nx/issues/12200#issuecomment-1291797897
For all you folks who are searching the web for Cannot read properties of null (reading 'message')
and pulling your hair out because your CI builds all of the sudden began failing:
The latest Gitlab update to Version 17 breaks NX's is-ci. I don't know why as the CI
and GITLAB_CI
variables are still provided FWIW, but it breaks 🤷
Adding ENV NX_DAEMON=false
to your Dockerfile
will fix it, thanks @Malagari !
EDIT: Looking at the latest changes to the is-ci
package, it may be due to this change: packages/nx/src/utils/is-ci.ts
Is this case related to logger_1.serverLogger.watcherLog('Unexpected workspace watcher error', error.message);
?
I'm having the same error when trying to start a nestJS api, when using the --verbose flag i got this
TypeError: Cannot read properties of null (reading 'message')
at handleWorkspaceChanges (/home/duwejeferson/repositorio/ibs-erp-3/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]/node_modules/nx/src/daemon/server/server.js:203:90)
at /home/duwejeferson/repositorio/ibs-erp-3/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]/node_modules/nx/src/daemon/server/watcher.js:39:9
If I execute a nx reset, the api start, but it doesn't restart with code changes, and if i kill it and try to execute again, the same error occurs.
Didn't debug any further. Maybe a should open a new Issue?
PS: I'm using Windows 11 with Ubuntu 22.04 on WSL
Is this case related to
logger_1.serverLogger.watcherLog('Unexpected workspace watcher error', error.message);
? I'm having the same error when trying to start a nestJS api, when using the --verbose flag i got thisTypeError: Cannot read properties of null (reading 'message') at handleWorkspaceChanges (/home/duwejeferson/repositorio/ibs-erp-3/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]/node_modules/nx/src/daemon/server/server.js:203:90) at /home/duwejeferson/repositorio/ibs-erp-3/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]/node_modules/nx/src/daemon/server/watcher.js:39:9
If I execute a nx reset, the api start, but it doesn't restart with code changes, and if i kill it and try to execute again, the same error occurs.
Didn't debug any further. Maybe a should open a new Issue?
PS: I'm using Windows 11 with Ubuntu 22.04 on WSL
Adding a ? on error?.message
"resolved" my issue, the API restarts properly with code changes now. 🤷♂️
I'm having the same issues as @duwejeferson on Ubuntu 22.04. I've tried using NPM, Yarn, and Bun, all with the same error as mentioned by @duwejeferson. I'm not using NextJS, but nx-dotnet. Seems to be an issue within Nx itself. Here's the block that brings the issue (nx/src/daemon/server/server.js:201
):
if (err || !changeEvents || !changeEvents.length) {
let error = typeof err === 'string' ? new Error(err) : err;
logger_1.serverLogger.watcherLog('Unexpected workspace watcher error', error.message);
console.error(error);
workspaceWatcherError = error;
return;
}
The issue seems to be that we can enter the if-statement's body if err
is falsy if one of the other conditions is true, and when it is falsy, error.message
will always fail.
Just found that this should be fixed in 19.1.0: https://github.com/nrwl/nx/pull/23500
is this still an existing issue?
At least not for me. I resolved the issue by upgrading to 19.1.0
Hi, I'm experiencing this with nx 18.3.5 I'm running nx on my WSL like @duwejeferson
Linux 6.6.36.3-microsoft-standard-WSL2 x86_64 GNU/Linux Distributor ID: Ubuntu Description: Ubuntu 20.04.6 LTS Release: 20.04 Codename: focal
workaround provided by @gcko is working fine for me for nx 18.3.5
Will give a try to 19.x
Closing as the issue has been fixed with an update.
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.