Skip to content
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

bug in readme? #439

Open
scippio opened this issue Sep 5, 2023 · 4 comments
Open

bug in readme? #439

scippio opened this issue Sep 5, 2023 · 4 comments

Comments

@scippio
Copy link

scippio commented Sep 5, 2023

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,
);
@aikoven
Copy link
Contributor

aikoven commented Sep 11, 2023

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?

@scippio
Copy link
Author

scippio commented Sep 12, 2023

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.
			*/
....

@aikoven
Copy link
Contributor

aikoven commented Sep 13, 2023

So what triggers this error is this setting:

"importsNotUsedAsValues": "error"

Thanks for the report! I will fix the readme.

@scippio
Copy link
Author

scippio commented Sep 13, 2023

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 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants