I've created npm package
package.json:
{
"name": "playwrightlib",
"version": "0.0.7",
"description": "Lib with playwright dependency",
"repository": "git@github.com:DonTomato/playwrightlib.git",
"author": "myemail@gmail.com",
"license": "MIT",
"type": "module",
"exports": "./src/index.js",
"files": [
"src",
"*.md"
],
"engines": {
"node": "^16.15.0"
},
"dependencies": {
"jest": "^29.5.0",
"@playwright/test": "^1.28.1"
}
}
It contains src folder with two files:
index.js:
export { testAbout } from './actions';
And actions.js:
import { expect } from '@playwright/test';
/**
* test About page
* @param {object} page - current page
*/
export async function testAbout(page) {
await page.goto('/about');
await expect(page.getByRole('heading', { name: 'About this app' })).toBeVisible();
}
When I try to use it with import { testAbout } from 'playwrightlib';
it returns the following error:
Error: Cannot find module 'C:...\node_modules\playwrightlib\src\actions' imported from C:...\node_modules\playwrightlib\src\index.js
Why? And how to fix it?