niieani / puppeteer-intercept-and-modify-requests

The best way to intercept and modify requests done by a Chromium website when instrumented by puppeteer
Apache License 2.0
48 stars 8 forks source link

Can not found module on esm/urlPattern #19

Closed xpader closed 1 year ago

xpader commented 1 year ago

package.json type is module. node version v16.14.2.

import { RequestInterceptionManager } from "puppeteer-intercept-and-modify-requests"

report this error:

Cannot find module './node_modules/puppeteer-intercept-and-modify-requests/esm/urlPattern' imported from ./node_modules/puppeteer-intercept-and-modify-requests/esm/main.js

in main.js, when modify import { getUrlPatternRegExp } from './urlPattern'; add .js suffix to import { getUrlPatternRegExp } from './urlPattern.js';, everythings ok now.

xpader commented 1 year ago

I found a document here:

Relative specifiers like './startup.js' or '../config.mjs'. They refer to a path relative to the location of the importing file. The file extension is always necessary for these.

https://nodejs.org/api/esm.html#import-specifiers:~:text=Relative%20specifiers%20like%20%27./startup.js%27%20or%20%27../config.mjs%27.%20They%20refer%20to%20a%20path%20relative%20to%20the%20location%20of%20the%20importing%20file.%20The%20file%20extension%20is%20always%20necessary%20for%20these.

xpader commented 1 year ago

Change urlPattern to urlPattern.js in main.ts is worked, but that's incredible. see https://github.com/microsoft/TypeScript/issues/40878

niieani commented 1 year ago

Fixed by #25.