webdriverio / webdriverio

Next-gen browser and mobile automation test framework for Node.js
http://webdriver.io
MIT License
9.04k stars 2.5k forks source link

[🐛 Bug]: babel transpiling not working #11004

Closed piotrblasiak closed 1 year ago

piotrblasiak commented 1 year ago

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

latest

Node.js Version

latest

Mode

Standalone Mode

Which capabilities are you using?

No response

What happened?

According to the documentation (https://webdriver.io/docs/babel/) having a babel.config.js should enable babel transpiling, but when I do it still asks for ts-node. Is babel still supported? And if both babel and ts-node are present (because the project needs it), how do I make sure only babel is being used? I need babel for its plugins (relay) that are required to compile some graphql tags.

What is your expected behavior?

No response

How to reproduce the bug.

https://github.com/attendium/wdio-babel-bug

npm run test

Relevant log output

npm run test                  

> wdio-mocha-bug@1.0.0 test
> wdio run ./test/unit/wdio.conf.ts

node:internal/errors:491
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'ts-node' imported from /Users/piotr/Documents/wdio-babel-bug/
    at new NodeError (node:internal/errors:400:5)
    at packageResolve (node:internal/modules/esm/resolve:823:9)
    at moduleResolve (node:internal/modules/esm/resolve:872:20)
    at defaultResolve (node:internal/modules/esm/resolve:1087:11)
    at nextResolve (node:internal/modules/esm/loader:161:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:834:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:415:18)
    at ESMLoader.import (node:internal/modules/esm/loader:516:22)
    at loadModulesInIsolation (node:internal/process/esm_loader:92:34)
    at initializeLoader (node:internal/process/esm_loader:61:25) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v19.3.0

Code of Conduct

Is there an existing issue for this?

erwinheitzman commented 1 year ago

I'm not sure what setup you use but since the wdio config is written using typescript, it will therefore use ts-node. I think that things will work when you change the config to be javascript

piotrblasiak commented 1 year ago

I'm not sure what setup you use but since the wdio config is written using typescript, it will therefore use ts-node. I think that things will work when you change the config to be javascript

Ok, thanks - and how can I make sure babel is being run, and not ts-node if both are installed?

piotrblasiak commented 1 year ago

I've also updated the test project with a test that shows that babel, even if it is being run - doesn't seem to run any of its plugins?

erwinheitzman commented 1 year ago

Okay so I have created a dummy project locally and if you want to use Babel + Typescript you can have .ts files but you will have to transpile the files using babel and then run the tests with the output out of babel

erwinheitzman commented 1 year ago

Basically do the same as this setup but for your tests: https://github.com/Microsoft/TypeScript-Babel-Starter

The end would look like:

wdio run ./lib/wdio.conf.js
piotrblasiak commented 1 year ago

Oh, I see. Ok makes sense, altho I was hoping to avoid that. Thanks!