Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Package subpath './koa' is not defined #5154

Open
botagar opened this issue Dec 26, 2023 · 4 comments
Open

[Bug]: Package subpath './koa' is not defined #5154

botagar opened this issue Dec 26, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@botagar
Copy link

botagar commented Dec 26, 2023

Version

System:                                                                                      
OS: Linux 5.10 Debian GNU/Linux 11 (bullseye) 11 (bullseye)                                
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz                                     
Memory: 21.01 GB / 24.70 GB                                                                
Container: Yes                                                                             
Shell: 5.1.4 - /bin/bash             
                                                    
npmPackages:                                                                                 
@modern-js/app-tools: 2.43.0 => 2.43.0                                                     
@modern-js/builder-rspack-provider: 2.43.0 => 2.43.0                                       
@modern-js/eslint-config: 2.43.0 => 2.43.0                                                 
@modern-js/plugin-bff: 2.43.0 => 2.43.0                                                    
@modern-js/plugin-koa: 2.43.0 => 2.43.0                                                    
@modern-js/runtime: 2.43.0 => 2.43.0                                                       
@modern-js/tsconfig: 2.43.0 => 2.43.0

node -v 
v18.19.0

yarn -v
1.22.21

Details

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.

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 globally npm 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.

@botagar botagar added the bug Something isn't working label Dec 26, 2023
@botagar
Copy link
Author

botagar commented Dec 26, 2023

Following this up, I tried again using Webpack and Express and got the same error, but for express.

error   Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './express' is not defined by "exports" in /path/.....

@chist3r
Copy link

chist3r commented Dec 30, 2023

Faced same issue, changed all imports from @modern-js/runtime/express to @modern-js/runtime/server and I'm able to build

@botagar
Copy link
Author

botagar commented Dec 30, 2023

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 😅

@zllkjc
Copy link
Member

zllkjc commented Jan 17, 2024

Thanks for the feedback, let's fix this document problem, and welcome PR~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants