liady / webpack-node-externals

Easily exclude node modules in Webpack
MIT License
1.3k stars 62 forks source link

[đź’ˇDeprecationWarning] webpack 5 externals-function should be defined like ({context, request}, cb) => { ... } #82

Closed thisVioletHydra closed 4 years ago

thisVioletHydra commented 4 years ago

terminal warning

webpack is watching the files…

(node:4516) [DEP_WEBPACK_EXTERNALS_FUNCTION_PARAMETERS] DeprecationWarning: The externals-function should be defined like ({context, request}, cb) => { ... }
(Use `node --trace-deprecation ...` to show where the warning was created)

image

What I should do?

liady commented 4 years ago

@thisVioletHydra which package version are you using? This should have been resolved in v2.5.0.

thisVioletHydra commented 4 years ago

@thisVioletHydra which package version are you using? This should have been resolved in v2.5.0.

"dependencies": {
    "axios": "^0.19.2",
    "axios-digest": "^0.1.1",
    "chalk": "4.1.0",
    "chokidar": "^3.4.2",
    "clean-webpack-plugin": "^3.0.0",
    "cors": "^2.8.5",
    "crypto-js": "^4.0.0",
    "defer-to-connect": "^2.0.0",
    "digest-fetch": "^1.1.1",
    "dotenv-webpack": "2.0.0",
    "eslint-plugin-node": "^11.1.0",
    "express": "^4.17.1",
    "fast-async": "^6.3.8",
    "fast-xml-parser": "3.17.4",
    "ip": "^1.1.5",
    "ipaddr.js": "^1.9.1",
    "is-cidr": "4.0.0",
    "jsonwebtoken": "^8.5.1",
    "lodash": "4.17.19",
    "module-alias": "^2.2.2",
    "moment": "2.27.0",
    "mongodb": "3.6.0",
    "mongoose": "5.9.28",
    "netmask": "^1.0.6",
    "node-notifier": "^7.0.2",
    "nodemailer": "6.4.11",
    "nodemon-webpack-plugin": "4.3.2",
    "terser-webpack-plugin": "^4.1.0",
    "uuid": "^8.3.0",
    "validate.js": "^0.13.1",
    "webpack": "^5.0.0-beta.26",
    "webpack-cli": "3.3.12",
    "webpack-dev-middleware": "3.7.2",
    "webpack-hot-middleware": "2.25.0",
    "webpack-node-externals": "2.5.1",
    "yarn-check": "^0.0.3"
  },
  "devDependencies": {
    "@babel/cli": "7.10.5",
    "@babel/core": "^7.11.1",
    "@babel/node": "7.10.5",
    "@babel/preset-env": "^7.11.0",
    "babel-eslint": "10.1.0",
    "babel-loader": "^8.1.0",
    "babel-plugin-module-resolver": "^4.0.0",
    "babel-preset-airbnb": "^5.0.0",
    "babel-watch": "^7.0.0",
    "cache-loader": "^4.1.0",
    "cross-env": "7.0.2",
    "eslint": "7.6.0",
    "eslint-config-airbnb-base": "14.2.0",
    "eslint-config-prettier": "6.11.0",
    "eslint-import-resolver-babel-module": "^5.1.2",
    "eslint-plugin-import": "2.22.0",
    "eslint-plugin-jsdoc": "^30.2.4",
    "eslint-plugin-json": "^2.1.2",
    "eslint-plugin-package-json": "^0.1.4",
    "eslint-plugin-prettier": "3.1.4",
    "eslint-plugin-promise": "^4.2.1",
    "friendly-errors-webpack-plugin": "^1.7.0",
    "jsdoc": "^3.6.5",
    "node-fetch": "^2.6.0",
    "prettier": "2.0.5",
    "test-webpack-reporter-plugin": "^1.0.2",
    "webpackbar": "^4.0.0"
  },
  "optionalDependencies": {
    "fsevents": "^2.1.2"
  }
thisVioletHydra commented 4 years ago

In webpack 5 it says that a notation like externals: [nodeExternals ()], is not correct, and you need to specify it according to the new type schema

liady commented 4 years ago

Apparently they check the function's signature as well. It is now fixed in v2.5.2. Thank you

skjnldsv commented 3 years ago

Hey! For me this is still throwing :thinking: "webpack-node-externals": "^2.5.2"

[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration[1].externals should be one of these:
   [RegExp | string | object { <key>: [non-empty string, ...] | boolean | string | object { … } } | function, ...] | RegExp | string | object { <key>: [non-empty string, ...] | boolean | string | object { … } } | function
   -> Specify dependencies that shouldn't be resolved by webpack, but should become dependencies of the resulting bundle. The kind of the dependency depends on `output.libraryTarget`.
   Details:
    * configuration[1].externals['0'] should be one of these:
      [non-empty string, ...] | boolean | string | object { … }
      -> The dependency used for the external.
      Details:
       * configuration[1].externals['0'] should be an array:
         [non-empty string, ...]
       * configuration[1].externals['0'] should be a boolean.
         -> `true`: The dependency name is used as target of the external.
       * configuration[1].externals['0'] should be a string.
         -> The target of the external.
       * configuration[1].externals['0'] should be an object:
         object { … }

Any clue?

liady commented 3 years ago

@skjnldsv Can you share your configuration? Can you also try and pass it as a function and not as an array with a function?

{
  ...
  externals: nodeExternals(), // not inside an array
  ...
}
skjnldsv commented 3 years ago

Ah, sorry I was keeping it inside the array as you mentioned before. I thought that was still the recommended way :) Thanks, I'll try later 🤗