pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.61k stars 344 forks source link

Getting `Cannot find module 'dsl/message'` error in 10.2.0 #974

Closed qmg-akara closed 1 year ago

qmg-akara commented 1 year ago

Hi guys, thanks for the great work!

We just upgraded to version 10.2.0 but our yarn lint is failing due to 2 import paths:

node_modules/.store/@pact-foundation-pact-npm-10.2.0-8ecf80a526/node_modules/@pact-foundation/pact/src/dsl/verifier/proxy/types.d.ts:4:34 - error TS2307: Cannot find module 'dsl/message' or its corresponding type declarations.

4 import { MessageProviders } from 'dsl/message';
                                   ~~~~~~~~~~~~~

node_modules/.store/@pact-foundation-pact-npm-10.2.0-8ecf80a526/node_modules/@pact-foundation/pact/src/dsl/verifier/types.d.ts:2:40 - error TS2307: Cannot find module 'dsl/options' or its corresponding type declarations.

2 import { MessageProviderOptions } from 'dsl/options';
                                         ~~~~~~~~~~~~~

Are aliased import paths typo or intentional?

Software versions

Please provide at least OS and version of pact-js

Issue Checklist

Please confirm the following:

Expected behaviour

No linting error

Actual behaviour

Getting the above errors

Steps to reproduce

It can be tested with a fresh install

Relevant log files

See above

mefellows commented 1 year ago

Gah! I really need to find a way to prevent my editor from using aliased imports, and investigate if this can be easily added to our CI to fail a build.

I'll get a patch out ASAP.

(also, thank you for the kind words)

qmg-akara commented 1 year ago

Thanks for the quick fix!

mefellows commented 1 year ago

You're welcome

TimothyJones commented 1 year ago

The problem is that if you're using aliases or a baseurl typescript doesn't convert the import paths on compilation, and as far as I know you can't make it convert them (unless you compile with something like babel or webpack as a post processing step)

I really need to find a way to prevent my editor from using aliased import

I don't remember which editor you use, but in VS Code this is under TypeScript › Preferences: Import Module Specifier.

Not using baseUrl at all is another solution, of course. It probably shouldn't be set in a library anyway.

TimothyJones commented 1 year ago

I guess this isn't picked up at test time because ts-jest just runs the typescript :/

mefellows commented 1 year ago

I don't remember which editor you use, but in VS Code this is under TypeScript › Preferences: Import Module Specifier.

Ah yes, thanks - I've made that change now.

Not using baseUrl at all is another solution, of course. It probably shouldn't be set in a library anyway.

Removing this makes it a compilation error, which I think is what we want (I added that change in yesterday, and found two more imports). Thanks for the tips everyone.

TimothyJones commented 1 year ago

I read the docs for that option after my comment last night, and it is there in typescript as a convenience for systems that use a different import structure or have a post processing step that moves files around. So we shouldn’t have had it set anyway. Probably my fault, sorry!