0

Here are key fields from webpack and ts configs:

webpack:

module: {
    rules: [
      {
        test: /\.ts$/,
        use: "ts-loader",
        exclude: /node_modules/,
      },
    ],
output: {
    path: __dirname + "/dist",
    filename: "bundle.js",
    library: "bundle",
    libraryTarget: "umd",
    umdNamedDefine: true,
    clean: true,
  },

tsconfig:

{
  "compilerOptions": {
    "resolveJsonModule": true,
    "target": "es6",
    "moduleResolution": "node",
    "sourceMap": true,
    "declaration": true,
    "removeComments": false,
    "noImplicitAny": true,
    "esModuleInterop": true,
    "outDir": "dist/"
  },

The entire project has been written in CommonJs and Typescript; now requirement is to support ESM for this run-time file (script.mjs/script.js/script.cjs) :

node bundle.js  -f <script.mjs>

I tried keeping the context in CommonJS (without type:module in package.json) but couldn't figure out the webpack config that would support that (libraryTarget: "?").

I tried changing context to ESM too (type: module in package.json; fixing requires and default exports, file extensions on imports) but that resulted in spree of errors; final one being "missing selenium driver".

Did you mean to import "selenium-webdriver/proxy.js"?
    at finalizeResolution (node:internal/modules/esm/resolve:275:11)
    at moduleResolve (node:internal/modules/esm/resolve:860:10)
    at defaultResolve (node:internal/modules/esm/resolve:984:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:685:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:634:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:617:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:273:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:135:49) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: '..../node_modules/selenium-webdriver/proxy'
}

Could someone please recommend what would be the best approach for this and in both approaches what should be the webpack and tsconfigs fields?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.