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

Can't get angular to work with protobuf #2373

Closed
jiaqi opened this issue Dec 30, 2020 · 5 comments
Closed

Can't get angular to work with protobuf #2373

jiaqi opened this issue Dec 30, 2020 · 5 comments
Labels
Can Close? We will close this in 30 days if there is no further activity

Comments

@jiaqi
Copy link

jiaqi commented Dec 30, 2020

🐞 bug report

Affected Rule

The issue is presented the rule: rollup_bundle but it occurs when multiple rules combine to support angular and protobuf so it's hard to say the problem is isolated in a single rule.

Is this a regression?

Yes, this bug was not present before this change where various rules and dependencies were upgraded.

Description

When an angular(10.0.0) app depends on protobuf ts library as demo'ed in this PR, the import statement of proto is not resolved by rollup_bundle.

🔬 Minimal Reproduction

Checkout the branch(https://github.com/jiaqi/angular-on-java/tree/proto) of the demo PR, build with

bazel build webapp/aoj:js_bundle.

Open the result file

less bazel-bin/webapp/aoj/js_bundle/index.js

The first line is

import { Thing } from 'angular_on_java/webapp/aoj/app/thing_pb';

If I understand it right, the import statements should all be resolved at this point.

🔥 Exception or Error

The build can pass but with --define=VERBOSE_LOGS=1 , we can see the warning showing that the proto ts library is not resolved.


...
(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
angular_on_java/webapp/aoj/app/thing_pb (imported by bazel-out/darwin-fastbuild/bin/webapp/aoj/app/app.mjs)

...

🌍 Your Environment

Operating System:

macOS 10.15.7

Output of bazel version:

bazel 3.7.1-homebrew

Rules_nodejs version:

2.3.2

Anything else relevant?

I'm using rules_nodejs 2.3.2 in this project. I haven't got 3.0.0 to work. Combining 3.0.0 with protobuf gave me a lot more trouble so I stopped trying. If that's the way to go I will file separate issue but let's keep the focus of this issue on rule_nodejs 2.3.* and protobuf. Thanks.

@jiaqi
Copy link
Author

jiaqi commented Jan 1, 2021

It turns out if I import pb with relative path it works well. e.g.

import { Thing } from './thing_pb';

The full path used to work but now it doesn't.
I can get around the problem now but in some TS code I have to import from long path like ../../../../some/dir/my_proto_pb to get it work.

@mattem
Copy link
Collaborator

mattem commented Jan 7, 2021

The linked change shows a bump to rules_nodejs > 2.0.0, this version included a change to not link the root of the workspace. iirc rollups default behavior is to treat unresolvable modules as external, which is then what is happening here.

It's possible to add link_workspace_root = True to rollup_bundle to allow it to resolve the import, or perhaps some custom resolving in the rollup config.

@jiaqi
Copy link
Author

jiaqi commented Jan 10, 2021

Confirmed that adding link_workspace_root = True solves the problem. Thanks for following up, @mattem .

I'm curious, shouldn't such problem cause the build of rollup_bundle to fail?

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had any activity for 90 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!

@github-actions github-actions bot added the Can Close? We will close this in 30 days if there is no further activity label Apr 11, 2021
@github-actions
Copy link

This issue was automatically closed because it went two weeks without a reply since it was labeled "Can Close?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Can Close? We will close this in 30 days if there is no further activity
Projects
None yet
Development

No branches or pull requests

2 participants