protobuf.js icon indicating copy to clipboard operation
protobuf.js copied to clipboard

sveltekit: TypeError: Cannot read properties of undefined (reading 'default')

Open MineYuanlu opened this issue 11 months ago • 4 comments
trafficstars

protobuf.js version: 7.4.0

using svelte(kit)

pbjs -t static-module -w es6 -l -o ./src/lib/protos/index.js ./protos/*.proto && pbts -o ./src/lib/protos/index.d.ts ./src/lib/protos/index.js
import * as $protobuf from "protobufjs/minimal";

// Common aliases
const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;

// Exported root namespace
const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});

error:

[vite] Error when evaluating SSR module /src/lib/protos/index.js:
|- TypeError: Cannot read properties of undefined (reading 'default')
    at ./src/lib/protos/index.js:7:30
    at async instantiateModule (file://./node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:52972:5)

MineYuanlu avatar Dec 03 '24 08:12 MineYuanlu

add: "protobufjs-cli": "^1.1.3"

test:

BAD:

import * as $protobuf from "protobufjs/minimal";

GOOD:

import $protobuf from "protobufjs/minimal";

MineYuanlu avatar Dec 03 '24 09:12 MineYuanlu

@MineYuanlu did you find a workaround?

github-herve-bourzeix avatar Jan 29 '25 15:01 github-herve-bourzeix

did you find a workaround?

@github-herve-bourzeix

I manually modified the code, and it works fine as long as it's changed like this:

import $protobuf from 'protobufjs/minimal';

MineYuanlu avatar Jan 29 '25 17:01 MineYuanlu

Thanks, I could fix the issue using a sed script after compilation, any chance that we get it fixed on a new release?

maelp avatar Jun 10 '25 07:06 maelp