During a Bazel build of a NextJs project I get a error related to cjs react.
Generating static pages (0/3)TypeError: Cannot read properties of null (reading 'useContext')
at Object.exports.useContext (apps/landing/node_modules/react/cjs/react.production.min.js:24:118)
The BUILD file for the package looks like this:
load("@landing-npm//next:index.bzl", "next")
filegroup(
name = "config",
srcs = [
".eslintrc.json",
"next.config.js",
"next-env.d.ts",
"package.json",
"tsconfig.json",
"yarn.lock",
],
)
filegroup(
name = "project",
srcs = glob([
"pages/**/*.ts",
"pages/**/*.tsx",
"public/*",
"styles/*",
]),
)
next(
name = "build",
args = [
"build",
"apps/landing",
],
data =
[
"config",
"project",
"@landing-npm//:node_modules",
],
)
Furthermore, the WORKSPACE has loaded the rules_nodejs with a repository of node_version = 16.15.1 and yarn_version = 1.22.19
The apps/landing is a project created with the next cli create --typescript default configuration.
I'm passing all the node_modules dependencies as data, so I don't think it is related to missing dependencies. Does anyone have some ideas on what could be creating this error and how it could be solved?