-
Notifications
You must be signed in to change notification settings - Fork 132
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
Using with Svelte-Kit, error: "The requested module does not provide an export name" #94
Comments
Hi Frederik, not sure what is going on - I can't reproduce, unfortunately: I just created a simple app with Then generated a simple message from msg-scalar.proto: npx protoc -I . --ts_opt long_type_string --ts_out ./src msg-scalar.proto And use the message in App.tsx: import {ScalarValuesMessage} from './msg-scalar';
console.log(
ScalarValuesMessage.create()
);
Vite 2.1.5, Typescript 4.2.3 got installed and tsconfig.json looks ok: {
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"types": ["vite/client"],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": ["./src"]
} This might be related to https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues It might be worth trying to set Do you have some more info so I can reproduce? |
This is the repo: https://github.com/frederikhors/protobuf-ts-issue-94. I used this cmd:
I'm using Win 10 64, node v14.16.0, npm v7.8.0. Steps: |
I can reproduce, thanks. The root cause seems to be a limitation of svelte's TypeScript preprocessor. It is not smart enough to figure out that an import of an interface for example can simply be omitted in Javascript. You have to explicitly use I am not sure whether I would consider this limitation acceptable. As a user, I don't want to think about whether I am using an import as a type or as a value. For example, I have to use import type {MyClass} from "./my-class";
let x: MyClass; But not in this case: import {MyClass} from "./my-class";
let x: MyClass = new MyClass(); The TypeScript compiler sorts this stuff out flawlessly by default. Maybe svelte should too. There is an easy workaround: npx protoc -I . --ts_opt long_type_string,force_optimize_code_size --ts_out ./src msg-scalar.proto
^^^^^^^^^^^^^^^^^^^^^^^^ If you use the plugin parameter I am not sure if this works in all cases, but it certainly does work with msg-scalar.proto. Could you give this workaround a try? If you notice any problems, let me know. |
I opened sveltejs/svelte-preprocess#340. Thank for your precious answer. I don't like workarounds. And I know this is not your fault! But I'm worried for two reasons:
Thanks again for all your work. |
Small note: I'm trying with the So not even in this way I can solve. |
Yes, see packages/benchmarks/perf.ts The difference in speed is surprisingly negligible.
|
Why is |
This is a microbenchmark, take it with a grain of salt 🙄 protobuf-ts is way more strict in JSON I/O than ts-proto and this costs some cycles. Note that you probably want to work with JSON strings, where most of the difference disappears. Also, you probably don't even want to use JSON, but the binary format. |
Version 2.0.0-alpha.18 was just published. This should generate It is very likely that there are some edge cases that don't work yet. Just let me know when you notice something missing. Cheers! |
I tried |
Thanks for the heads up, that was not intentional. 🔥 🚒 I could not unpublish in time. v1.0.13 fixes the "latest" channel, |
"You have to explicitly use import type in svelte to import types." Thank you @timostamm !! For anyone else who came here from a Google search I ran into this problem tonight, and I'm on: |
BTW, svelte apparently fixed this in v4.9.0, see sveltejs/svelte-preprocess#392 |
We were generating `import * as grpc from "@grpc/grpc-js";` were we should have been generating `import type * as grpc from "@grpc/grpc-js";`. See #94.
Hi @timostamm! Your work is great! Really, I'm speechless! ❤️
i tried both v1 and v2 (now I'm on
2.0.0-alpha.17
) and using https://vitejs.dev I get this error:and also for:
BinaryWriteOptions
IBinaryReader
IBinaryWriter
If I open the generated files and change this:
to this:
(and in the other file too... ex:
import type { RpcTransport } from "@protobuf-ts/runtime-rpc";
)it works!
Why?
How can I automagically fix this? With a
.tsconfig
option, maybe?The text was updated successfully, but these errors were encountered: