fireship-io/flamethrower

[help] cannot find imported module

depapp opened this issue ยท 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 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.

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 ? ๐Ÿ™๐Ÿป

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.

noted @sidwebworks , thank you ๐Ÿ™‡๐Ÿป

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.