Using with Svelte-Kit, error: "The requested module does not provide an export name"
See original GitHub issueHi @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:
The requested module '/node_modules/.vite/@protobuf-ts_runtime.js?v=e308126a' does not provide an export named 'BinaryReadOptions'
and also for:
BinaryWriteOptions
IBinaryReader
IBinaryWriter
- and so on…
If I open the generated files and change this:
import { ServiceType } from "@protobuf-ts/runtime-rpc";
import { BinaryWriteOptions } from "@protobuf-ts/runtime";
import { IBinaryWriter } from "@protobuf-ts/runtime";
import { WireType } from "@protobuf-ts/runtime";
import { BinaryReadOptions } from "@protobuf-ts/runtime";
import { IBinaryReader } from "@protobuf-ts/runtime";
import { UnknownFieldHandler } from "@protobuf-ts/runtime";
import { MessageType } from "@protobuf-ts/runtime";
to this:
import { ServiceType } from "@protobuf-ts/runtime-rpc";
import type { BinaryWriteOptions } from "@protobuf-ts/runtime";
import type { IBinaryWriter } from "@protobuf-ts/runtime";
import { WireType } from "@protobuf-ts/runtime";
import type { BinaryReadOptions } from "@protobuf-ts/runtime";
import type { IBinaryReader } from "@protobuf-ts/runtime";
import { UnknownFieldHandler } from "@protobuf-ts/runtime";
import { MessageType } from "@protobuf-ts/runtime";
(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?
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
"Does not provide an export named 'Tooltip'," even though I ...
SyntaxError: Named export 'Tooltip' not found. The requested module 'chart.js' is a CommonJS module, which may not support all module.exports as ...
Read more >Requested module does not provide export named 'default'
To solve the error "The requested module does not provide an export named default", use the `default` keyword when exporting a value from...
Read more >vite does not provide an export named - You.com - You.com
Facing the following error on. The requested module '/node_modules/.vite/deps/vue-router.js?v=4ee861bd' does not provide an export named 'default'.
Read more >Solved: Svelte Kit Build Error - Esri Community
Named export 'commitAssetPath' not found. The requested module '@esri/calcite-components/dist/custom-elements/utils.js' is a CommonJS module ...
Read more >Common Error Details - Snowpack
Uncaught SyntaxError: The requested module './XXXXXX.js' does not provide an export named 'YYYYYY'#. If you are using TypeScript, this error could occur if ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
import type
in svelte to import types. See this issue: https://github.com/sveltejs/svelte-preprocess/issues/206I 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
in this case:But not in this case:
The TypeScript compiler sorts this stuff out flawlessly by default. Maybe svelte should too.
There is an easy workaround:
If you use the plugin parameter
force_optimize_code_size
, protobuf-ts will use reflection for the binary format. This results in much smaller code size (you probably want this in a web app), and by coincidence the code only uses value imports.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.
Hi Frederik,
not sure what is going on - I can’t reproduce, unfortunately:
I just created a simple app with
npm init @vitejs/app
with thereact-ts
template.Then generated a simple message from msg-scalar.proto:
And use the message in App.tsx:
npm run dev
andnpm run build
work as expected, there are not compilation errors or warnings.Vite 2.1.5, Typescript 4.2.3 got installed and tsconfig.json looks ok:
This might be related to https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues
It might be worth trying to set
"importsNotUsedAsValues" : "remove"
(the default behaviour) in a tsconfig.json for the generated code.Do you have some more info so I can reproduce?