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

[Question] How to use a custom typescript package? #14343

Closed
LisBerndt opened this issue May 23, 2022 · 1 comment
Closed

[Question] How to use a custom typescript package? #14343

LisBerndt opened this issue May 23, 2022 · 1 comment

Comments

@LisBerndt
Copy link

LisBerndt commented May 23, 2022

Hello!

To execute some preparations we use a helper-package, written in typescript.
The sources of this package work fine when they are part of the source code of my playwright app. - I can import it, so that I can use it as a fixture e.g.
My idea was now to separate that package onto a verdaccio server to make it reusable for other playwright-projects. But here I am in tremendous trouble now.
The package itself works as expected, but after installing it and trying my playwright-app to run with it, I always get:

JavaScript files must end with .mjs to use import.

Interesting - I do not use any js-files.
Nevertheless, my naive approach here was, "ok... then I provide the files also with .mjs-extension." - But this fails as well.
I have read related topics, but I am not able to get it work.

That is my tsconfig.json

{
  "compilerOptions": {
    "strict": false,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "target":"ES2022",
    "moduleResolution": "Node"
  }
}

That is my config.json

{
  "name": "@private/resource_provider",
  "version": "1.0.12",
  "description": "",
  "main": "/resource_provider/resource_provider",
  "directories": {
    "test": "tests"
  },
  "devDependencies": {
    "@types/node": "^17.0.35",
    "gts": "^3.1.0",
    "tslib": "^2.4.0",
    "typescript": "^4.6.4"
  },
  "dependencies": {
    "node-fetch": "^2.6.7",
    "ts-node": "^10.7.0"
  },
  "scripts": {
    "test": "npx ts-node tests/test.ts"
  },
}

I confess, I am not that experienced with that config-stuff. - What is the best practice to integrate custom typescript packages?

PS: Using .js-extension as recommended here gives: Error: Cannot find module [...].js

@LisBerndt LisBerndt changed the title How to use a custom typescript package?[Question] [Question] How to use a custom typescript package? May 24, 2022
@pavelfeldman
Copy link
Member

This does not give me a good idea on what you are trying to do - your question seems to be not about Playwright, but about creating a custom typescript package. Node can't execute TypeScript, so there is no such thing as a "custom typescript package". You would need to compile your module into JS, preferably to CJS for better interoperability. I think I have a better idea on the linked issue, so we can continue this conversation there.

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