-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
protobuf.js version: 7.2.0
Trying to use protobufjs in an ES module.
{
"name": "myproject",
"version": "1.0.0",
"type": "module",
"dependencies": {
"protobufjs": "^7.2.0"
},
"devDependencies": {
"protobufjs-cli": "^1.1.0",
"typescript": "^4.9.5"
}
}
I generated the protobuf messages module (and typings) like this
npx pbjs -t static-module -w es6 protobuf/myproject.proto -o src/protobuf/protobuf.js
npx pbts src/protobuf/protobuf.js -o src/protobuf/protobuf.d.ts
At the top of the src/protobuf/protobuf.js file I see this:
/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
import * as $protobuf from "protobufjs/minimal";
Given a simple program
// src/main.ts
import { SomeMessage } from "src/protobuf.js"
console.log("Hello world!")
And compiling with this tsconfig.json:
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "nodenext",
"target": "ES2022",
"sourceMap": true,
"strict": true,
"skipLibCheck": true,
"outDir": "build",
"noImplicitAny": false,
"allowJs": true
},
"include": [
"src/**/*",
"tests/**/*"
]
}
When I try to run the project node --enable-source-maps build/main.js I get this error message:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/birger/myproject/node_modules/protobufjs/minimal' imported from /home/birger/myproject/build/src/protobuf/protobuf.js
Did you mean to import protobufjs/minimal.js?
Tbh I don't know if I correctly understood the process of generating the protobuf module with typings. Should I not be using the -w es6 flag?
xuxucode, Danieth, michal-kapala, hlwht, obicons and 9 more
Metadata
Metadata
Assignees
Labels
No labels