deeplay-io / nice-grpc

A TypeScript gRPC library that is nice to you

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug in readme?

scippio opened this issue · comments

Hello!

I tried generate example step-by-step with example codes and I get this error:
SyntaxError: The requested module '/src/lib/proto/example.ts' does not provide an export named 'ExampleServiceClient'
because ExampleServiceClient is generated only like interface...

So I think the right example from readme:

import {createChannel, createClient} from 'nice-grpc-web';
import {
  ExampleServiceClient,
  ExampleServiceDefinition,
} from './compiled_proto/example';

const channel = createChannel('http://localhost:8080');

const client: ExampleServiceClient = createClient(
  ExampleServiceDefinition,
  channel,
);

should be this:

import {createChannel, createClient} from 'nice-grpc-web';
import type { ExampleServiceClient } from './compiled_proto/example';
import { ExampleServiceDefinition } from './compiled_proto/example';

const channel = createChannel('http://localhost:8080');

const client: ExampleServiceClient = createClient(
  ExampleServiceDefinition,
  channel,
);

Hey,

This must have something to do with your tooling. With vanilla tsc you should be allowed to import types using regular import (not just import type).

I'm fine with making the proposed change to the docs, but I'd like to figure it out first.

Which bundler are you using?

I opened the tsconfig.json and I maybe found the reason (in comment) 😬 :

{
	"compilerOptions": {
		"moduleResolution": "node",
		"module": "es2020",
		"lib": ["es2020"],
		"target": "es2019",
		/**
			svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
			to enforce using \`import type\` instead of \`import\` for Types.
			*/
....

So what triggers this error is this setting:

"importsNotUsedAsValues": "error"

Thanks for the report! I will fix the readme.

This is my full tsconfig.json:

{
	"compilerOptions": {
		"moduleResolution": "node",
		"module": "es2020",
		"lib": ["es2020"],
		"target": "es2019",
		/**
			svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
			to enforce using \`import type\` instead of \`import\` for Types.
			*/
		// "importsNotUsedAsValues": "error",
		// "verbatimModuleSyntax": true,
		"isolatedModules": true,
		"resolveJsonModule": true,
		/**
			To have warnings/errors of the Svelte compiler at the correct position,
			enable source maps by default.
			*/
		"sourceMap": true,
		"esModuleInterop": true,
		"skipLibCheck": true,
		"forceConsistentCasingInFileNames": true,
		"baseUrl": ".",
		"allowJs": true,
		"checkJs": true,
		"paths": {
			"$lib":["src/lib"],
			"$lib/*":["src/lib/*"]
		}
	},
	"include": ["src/*.d.ts", "src/**/*.d.ts", "src/**/*.js", "src/**/*.ts", "src/**/*.svelte"],
	"extends": "./.svelte-kit/tsconfig.json"
}

importsNotUsedAsValues is deprecated: https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues so I think it's ok when I have it commented. So I think this problem is here because I'm using Svelte: svelte-preprocess ...