You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm getting an issue attempting to run a yarn build on a project that uses the useContext hook in a Functions BFF api.
Any time I include the context hook, the build fails with the following output:
me@DESKTOP:~/dev/modernjs-test$ yarn build
yarn run v1.22.21
warning package.json: No license field
$ modern build
Modern.js Framework v2.43.0
info Using Rspack v0.4.4
info Starting production build...
info ts checker running...
info ts checker is running slowly and will block builds until it is complete, please be patient and wait.
● Client ━━━━━━━━━━━━━━━━━━━━━━━━━ (10%) building ./lib/ReactPropTypesSecret
error Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './koa' is not defined by "exports" in /home/me/dev/modernjs-test/node_modules/@modern-js/runtime/package.json
at new NodeError (node:internal/errors:405:5)
at exportsNotFound (node:internal/modules/esm/resolve:366:10)
at packageExportsResolve (node:internal/modules/esm/resolve:713:9)
at resolveExports (node:internal/modules/cjs/loader:584:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:658:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1120:27)
at Function.import_module.default._resolveFilename (/home/me/dev/modernjs-test/node_modules/@modern-js/bff-core/dist/cjs/utils/alias.js:100:36)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue (/home/me/dev/modernjs-test/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
at Function.Module._resolveFilename (/home/me/dev/modernjs-test/node_modules/tsconfig-paths/src/register.ts:115:36)
at Function.Module._load (node:internal/modules/cjs/loader:975:27)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: write EPIPE
at target._send (node:internal/child_process:872:20)
at target.send (node:internal/child_process:745:19)
at /home/me/dev/modernjs-test/node_modules/fork-ts-checker-webpack-plugin/lib/rpc/expose-rpc.js:27:31
at new Promise (<anonymous>)
at sendMessage (/home/me/dev/modernjs-test/node_modules/fork-ts-checker-webpack-plugin/lib/rpc/expose-rpc.js:19:38)
at /home/me/dev/modernjs-test/node_modules/fork-ts-checker-webpack-plugin/lib/rpc/expose-rpc.js:60:27
at Generator.next (<anonymous>)
at fulfilled (/home/me/dev/modernjs-test/node_modules/fork-ts-checker-webpack-plugin/lib/rpc/expose-rpc.js:5:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
errno: -32,
code: 'EPIPE',
syscall: 'write'
}
Launching the same codebase in development mode works however (yarn dev) and the site functions as expected.
I would expect that the build should work in this case.
Faced same issue, changed all imports from @modern-js/runtime/express to @modern-js/runtime/server and I'm able to build
Thanks for that @chist3r ! I didn't think to try that and doing this enabled the build to work.
Not in a position yet to test that the output build works in a deployed environment, but building an output package is a good start 😆
So it seems then either the bug is:
The documentation is the issue and the following line import { useContext } from '@modern-js/runtime/{namespace}'; should be import { useContext } from '@modern-js/runtime/server';
OR
Both the Express and Koa exports need updating.
I'm not a deep node/js expert so I'll leave the fix to those who know what they are doing 😅
Version
Details
I'm getting an issue attempting to run a
yarn build
on a project that uses theuseContext
hook in a Functions BFF api.Any time I include the context hook, the build fails with the following output:
Launching the same codebase in development mode works however (
yarn dev
) and the site functions as expected.I would expect that the build should work in this case.
Reproduce link
https://github.com/botagar/modernjs-build-issue
Reproduce Steps
Create a new Web App as per the quickstart guide (https://modernjs.dev/en/guides/get-started/quick-start.html) using TS, Yarn, RS Pack.
Update all packages to latest published versions. I use
yarn-check -u
(needs to be installed globallynpm install -g yarn-check
).Enable BFF in Function mode (https://modernjs.dev/en/guides/advanced-features/bff/function.html) with Koa as the engine.
In any of the API functions, import the
useContext
hook (https://modernjs.dev/en/apis/app/runtime/bff/use-context.html) and use it for anything.Run a
yarn build
and watch it fail.The text was updated successfully, but these errors were encountered: