flamethrower icon indicating copy to clipboard operation
flamethrower copied to clipboard

[help] cannot find imported module

Open depapp opened this issue 2 years ago • 5 comments

hello everyone, I've tried to implement page object model for the playwright test, but I have an issue related to import module.

  • here's my code image

  • folder structure image

  • error message Error: Cannot find module '/Users/user/open-source/flamethrower/test/home.page' imported from /Users/user/open-source/flamethrower/test/main.spec.ts image

is there any missing configuration? thanks in advance for any help 🙏🏻

depapp avatar Aug 22 '22 04:08 depapp

@depapp You can't import a typescript file directly like a regular JS module, you'll have to add some sort of build step or directly execute the tests using vitest in that case it will automatically build your typescript code before running it.

sidwebworks avatar Aug 22 '22 21:08 sidwebworks

thanks for the help @sidwebworks 🙇🏻 there are some import on the /lib dir https://github.com/fireship-io/flamethrower/blob/main/lib/main.ts#L1 and it's works.

but the import didn't works on /test dir. do I need to update the tsconfig.json file to solve this import issue @sidwebworks ? 🙏🏻

depapp avatar Aug 23 '22 02:08 depapp

Those imports only work after building the typescript files.

To fix the problem you're facing, first build the project then import the module from the build/output directory into your test.

sidwebworks avatar Aug 23 '22 02:08 sidwebworks

noted @sidwebworks , thank you 🙇🏻

depapp avatar Aug 23 '22 02:08 depapp

Playwright is essentially just running chromium browser, just like you won't run typescript directly in the browser or Node its the same thing here.

sidwebworks avatar Aug 23 '22 02:08 sidwebworks