|
| 1 | +# protobuf-javascript: Try to reproduce "'proto' is not defined" |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This repository aims to reproduce the "'proto' is not defined" error as described in [_ReferenceError: proto is not defined #10_](https://github.com/protocolbuffers/protobuf-javascript/issues/10) to help the developers figure out whether there is a bug and, if there is, how to fix it. |
| 6 | + |
| 7 | +There two sub-directories: |
| 8 | + |
| 9 | +- `noejs` is a `node.js` native app that cannot reproduce the error. |
| 10 | +- `react-app` is a React.js app that can reproduce the error. |
| 11 | + |
| 12 | +I'll first mention the other existing work in the next section and then describe how to use these two apps. |
| 13 | + |
| 14 | +## Other work |
| 15 | + |
| 16 | +The issue [1] [_Failed to compile. 'proto' is not defined (also 'COMPILED') #447_](https://github.com/grpc/grpc-web/issues/447) in `grpc-web` mentions a similar problem that used TypeScript. The quick workaround was to disable `eslint` as mentioned [in this comment](https://github.com/grpc/grpc-web/issues/447#issuecomment-459122012). Others in the discussion also provided alternative workarounds. See [this](https://github.com/grpc/grpc-web/issues/447#issuecomment-460420957), [this](https://github.com/grpc/grpc-web/issues/447#issuecomment-491628171), [this](https://github.com/grpc/grpc-web/issues/447#issuecomment-564285432), [this](https://github.com/grpc/grpc-web/issues/447#issuecomment-568559394), and [this](https://github.com/grpc/grpc-web/issues/447#issuecomment-586668982). |
| 17 | + |
| 18 | +The issue also mentions the Pull Request [_Disable static checkers on generated js files #752_](https://github.com/grpc/grpc-web/pull/752). But note that this PR is for `grpc-web` so it only fixes the output of `--grpc-web_out` but not `--js_out`. |
| 19 | + |
| 20 | +But [1] gave me the hint to try to disable `eslint` in the React.js app and that did work around the issue. |
| 21 | + |
| 22 | +## How to use |
| 23 | + |
| 24 | +## Environment |
| 25 | + |
| 26 | +My environment: |
| 27 | +- Ubuntu 18.04 Desktop |
| 28 | +- `npm`: 6.14.15 |
| 29 | +- `yarn`: 1.22.15 |
| 30 | +- `node` (or `nodejs`): 14.18.2 |
| 31 | +- `google-protobuf`: 3.19.4 |
| 32 | + |
| 33 | +### `nodejs` |
| 34 | + |
| 35 | +`cd` into the sub-directory `nodejs` and run `run.sh`. This should print `good` at the end and doesn't report any error. |
| 36 | + |
| 37 | +### `react-app` |
| 38 | + |
| 39 | +There are two shell scripts: |
| 40 | +- `run-npm.sh` |
| 41 | +- `run-yarn.sh` |
| 42 | + |
| 43 | +Running `run-npm.sh` produced the following output (which suggests `eslint` might be the cause): |
| 44 | + |
| 45 | +``` |
| 46 | +Failed to compile. |
| 47 | +
|
| 48 | +[eslint] |
| 49 | +src/foo_pb.js |
| 50 | + Line 26:1: 'proto' is not defined no-undef |
| 51 | + Line 29:15: 'proto' is not defined no-undef |
| 52 | + Line 30:20: 'COMPILED' is not defined no-undef |
| 53 | + Line 31:3: 'proto' is not defined no-undef |
| 54 | + Line 46:1: 'proto' is not defined no-undef |
| 55 | + Line 47:10: 'proto' is not defined no-undef |
| 56 | + Line 60:1: 'proto' is not defined no-undef |
| 57 | + Line 78:1: 'proto' is not defined no-undef |
| 58 | + Line 80:17: 'proto' is not defined no-undef |
| 59 | + Line 81:10: 'proto' is not defined no-undef |
| 60 | + Line 92:1: 'proto' is not defined no-undef |
| 61 | + Line 116:1: 'proto' is not defined no-undef |
| 62 | + Line 118:3: 'proto' is not defined no-undef |
| 63 | + Line 130:1: 'proto' is not defined no-undef |
| 64 | + Line 146:1: 'proto' is not defined no-undef |
| 65 | + Line 152:1: 'proto' is not defined no-undef |
| 66 | + Line 157:29: 'proto' is not defined no-undef |
| 67 | +
|
| 68 | +Search for the keywords to learn more about each error. |
| 69 | +WARNING in [eslint] |
| 70 | +src/App.js |
| 71 | + Line 4:7: 'proj' is assigned a value but never used no-unused-vars |
| 72 | +
|
| 73 | +src/foo_pb.js |
| 74 | + Line 12:14: The Function constructor is eval no-new-func |
| 75 | + Line 61:7: 'f' is defined but never used no-unused-vars |
| 76 | + Line 80:13: Missing '()' invoking a constructor new-parens |
| 77 | +
|
| 78 | +ERROR in [eslint] |
| 79 | +src/foo_pb.js |
| 80 | + Line 26:1: 'proto' is not defined no-undef |
| 81 | + Line 29:15: 'proto' is not defined no-undef |
| 82 | + Line 30:20: 'COMPILED' is not defined no-undef |
| 83 | + Line 31:3: 'proto' is not defined no-undef |
| 84 | + Line 46:1: 'proto' is not defined no-undef |
| 85 | + Line 47:10: 'proto' is not defined no-undef |
| 86 | + Line 60:1: 'proto' is not defined no-undef |
| 87 | + Line 78:1: 'proto' is not defined no-undef |
| 88 | + Line 80:17: 'proto' is not defined no-undef |
| 89 | + Line 81:10: 'proto' is not defined no-undef |
| 90 | + Line 92:1: 'proto' is not defined no-undef |
| 91 | + Line 116:1: 'proto' is not defined no-undef |
| 92 | + Line 118:3: 'proto' is not defined no-undef |
| 93 | + Line 130:1: 'proto' is not defined no-undef |
| 94 | + Line 146:1: 'proto' is not defined no-undef |
| 95 | + Line 152:1: 'proto' is not defined no-undef |
| 96 | + Line 157:29: 'proto' is not defined no-undef |
| 97 | +
|
| 98 | +Search for the keywords to learn more about each error. |
| 99 | +
|
| 100 | +webpack compiled with 1 error and 1 warning |
| 101 | +``` |
| 102 | + |
| 103 | +Running `run-yarn.sh` produced the same output as `run-npm.sh`. |
0 commit comments