-
Notifications
You must be signed in to change notification settings - Fork 75
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
Unable to import @bufbuild/protobuf/codegenv1 in generated files. #953
Comments
I tried testing just the imports in an empty project. And still the same issue. import React from 'react';
import {Text} from 'react-native';
import { enumDesc, extDesc, fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv1";
export default function ModalScreen() {
console.log( enumDesc, extDesc, fileDesc, messageDesc, serviceDesc);
return (
<>
<Text>Hello world</Text>
</>
);
} Error Metro error: Unable to resolve module @bufbuild/protobuf/codegenv1 from /Users/hemant/projects/tmp/react_native_bp/custom-expo-app/app/index.tsx: @bufbuild/protobuf/codegenv1 could not be found within the project or in these directories:
node_modules
../node_modules
1 | import React from 'react';
2 | import {Text} from 'react-native';
> 3 | import { enumDesc, extDesc, fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv1";
| ^
4 |
5 | export default function ModalScreen() {
6 | So, im more sure that something is wrong with the package. |
Hey Hemant, there's a metro issue for supporting package.json exports: facebook/metro#670 It was resolved over a year ago. Can you check that your dependencies are up to date? We're testing the exports with webpack, vite, rollup, parcel, and esbuild here, and with TypeScript, Node.js and attw in this repository. It seems unlikely that the exports are wrong. |
Thanks for the pointer @timostamm, You are right, its a miss from Metro side! The support for package exports is still behind a feature flag. config.resolver.unstable_enableSymlinks = true;
config.resolver.unstable_enablePackageExports = true; My expo app now working fine with new 2.0.0 release. Thanks a ton! |
Update: So as soon I enable
in metro config, im not able to open any page and getting this error. While its directly not related to protobuf-es and mostly in metro. But metro doc states that the package exports feature is still unstable. So probably you want to provide a fallback way of importing this package. |
As an interim solution I have vendored the @bufbuild/protobuf module in the project and created a file export * from "../dist/esm/codegenv1/index.js"; and in my metro config I have added vendor dir config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, 'vendor'),
path.resolve(projectRoot, 'node_modules'),
]; Hoping to see a solution to this soon. |
This looks like in issue in If an update doesn't help, it's probably reasonable to vendor this package instead, since it's basically 15 lines of code. |
Is it possible to disable descriptor/reflection generated code in |
Just to confirm as pointed by @timostamm adding below to package.json and then enabling "resolutions": {
"use-latest-callback": "0.2.1"
}, |
I’m running into this issue using the worker example and PNPM. NPM works fine but when I delete node_modules, package-lock.json and try and install using pnpm it throws:
EDIT: fixed by installing @connectrpc/connect @connectrpc/connect-web @bufbuild/protobuf |
Hi Team,
Thanks for excellent work here.
Im generating the .ts files using buf, here is my configuration
I imported the generated files in my expo based project. But when I run the project it throws below error.
I verified the @bufbuild/protobuf is available in node_modules also did the cache cleanup. Even wrote a custom resolver for metro. But the error is still there.
Im not sure where to report this and whether this is an issue in the export config of bufbuild/protobuf.
Any help will be appreciated.
The text was updated successfully, but these errors were encountered: