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

error after vite building

Open CodeBiang opened this issue 3 years ago • 13 comments

protobuf.js version: <^6.11.2>

something undefined after vite building

((Field$6.prototype=Object.create(ReflectionObject$5.prototype)).constructor=Field$6).className="Field";var Enum$9=_enum,types$4=types$5,util$f=util$g.exports,Type$5,ruleRe=/^required|optional|repeated$/;Field$6.fromJSON=function H(C,K){return new Field$6(C,K.id,K.type,K.rule,K.extend,K.options,K.comment)};function Field$6(H,C,K,U,W,G,X){if(util$f.isObject(U)?(X=W,G=U,U=W=void 0

the code has been compressed, but it's easily to see that this is a part of the protobufjs

it work properly in development mode.

no idea

CodeBiang avatar Dec 08 '21 15:12 CodeBiang

ReflectionObject$5 is undefined

CodeBiang avatar Dec 08 '21 15:12 CodeBiang

Same problem here. Using SvelteKit (1.0.0-next.202), protobufjs 6.11.2, vite 2.7.3.

oliversturm avatar Dec 16 '21 16:12 oliversturm

Worked around it for now using the minimal build and a static code module. Bit fiddly though because the generated code isn't appreciated by the build either - used this sed command to replace the standard import code with something that works (note that the $$ is due to placement of the command in a makefile):

sed -i -e 's|import \* as $$protobuf from "protobufjs/minimal"|import $$protobuf from "protobufjs/minimal.js"|' $(DATAPATH)/the.proto.js

To be clear for those who may find this helpful but who don't read sed, the command replaces the generated import line

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

with this:

import $protobuf from "protobufjs/minimal.js";

I found both changes necessary - the slightly different import syntax and the explicit .js file extension. YMMV.

oliversturm avatar Dec 17 '21 13:12 oliversturm

Waiting for good news~

melunar avatar Jan 18 '22 08:01 melunar

same problem here

songzhj avatar Mar 30 '22 06:03 songzhj

same problem here

JangCool avatar Apr 19 '22 00:04 JangCool

me too

notfound945 avatar Apr 23 '22 09:04 notfound945

me too

jinzhongjia avatar Apr 30 '22 02:04 jinzhongjia

import * as $protobuf from "protobufjs/minimal"

I found a way to temporarily solve this problem,you can replace

import { roots, Root } from "protobufjs/light";

with

import { roots, Root } from "protobufjs/dist/light/protobuf.min";

i dont konw if this is right,but it does work the now code is import the builded protobufjs,skipped live build phase

jinzhongjia avatar Apr 30 '22 02:04 jinzhongjia

import * as $protobuf from "protobufjs/minimal"

I found a way to temporarily solve this problem,you can replace

import { roots, Root } from "protobufjs/light";

with

import { roots, Root } from "protobufjs/dist/light/protobuf.min";

i dont konw if this is right,but it does work the now code is import the builded protobufjs,skipped live build phase

This is only a temporary workaround

jinzhongjia avatar Apr 30 '22 02:04 jinzhongjia

me too

iaa3906 avatar May 18 '22 11:05 iaa3906

I have a same problem with version 7.0.0 and 6.11.3

TypeError: Cannot read properties of undefined` after `vite build

and undefined is caused by _m0.util and the following import

import * as _m0 from "protobufjs/minimal.js";

In the end, I fixed this issue. Just I imported wrongly in files before building

//import * as _m0 from "protobufjs/minimal.js";
import _m0 from "protobufjs/minimal.js";

hiromaily avatar Jul 09 '22 15:07 hiromaily