Estoy tratando de usar el paquete sanitize-html junto con @types/sanitize-html para mecanografiar, pero provoca el siguiente error:
ERROR in ./node_modules/postcss/lib/input.js 4:30-45 Module not found: Error: Can't resolve 'path' in 'C:\Users\sapin\Desktop\gatsby-starter-hello-world\node_modules\postcss\lib' BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "path": false } @ ./node_modules/postcss/lib/postcss.js 14:12-30 @ ./node_modules/sanitize-html/index.js 7:32-50 @ ./src/states/BlogsProvider.tsx 12:0-37 103:15-23 104:21-29 105:14-22 @ ./src/pages/bookmarks.tsx 10:0-51 18:24-32 61:10-18 @ ./.cache/_this_is_virtual_fs_path_/$virtual/async-requires.js 36:11-38:5 @ ./.cache/app.js 17:0-52 28:0-70 30:27-40 28:0-70 Y si hago npm i path , el error de tiempo de compilación desaparece; pero causa un error de tiempo de ejecución-
Uncaught ReferenceError: process is not defined at eval (path.js:25) at Object../node_modules/path/path.js (commons.js:2976) at Object.options.factory (commons.js:4478) at __webpack_require__ (commons.js:3881) at fn (commons.js:4159) at eval (map-generator.js:3) at Object../node_modules/postcss/lib/map-generator.js (commons.js:3096) at Object.options.factory (commons.js:4478) at __webpack_require__ (commons.js:3881) at fn (commons.js:4159)Rastreando la línea de error, es esta la que arroja el error-
var isWindows = process.platform === 'win32'; En resumen , el paquete sanitize-html no puede reconocer path sin instalarla explícitamente. Cuando está instalado, el módulo de path no puede reconocer process . ¿Cómo puedo arreglar esto?
Si no, ¿hay algún paquete de desinfección alternativo que admita mecanografiado?
El problema se solucionó en la v8.2.7 , según este comentario en GitHub. Parece estar relacionado con el hecho de que webpack eliminó los polyfills en su nueva versión v5 , que es una dependencia necesaria de postcss , que también es utilizada por sanitize-html .
Sin embargo, si el problema persiste, debe solucionarse instalando path-browserify (mediante npm i path-browserify ) y agregando el siguiente respaldo a la configuración principal de webpack, en su gatsby-node.js , onCreateWebpackConfig API debería funcionar:
exports.onCreateWebpackConfig = ({ actions }) => { actions.setWebpackConfig({ resolve: { fallback: { path: require.resolve('path-browserify'), }, }, }) }Fuente: modificado de https://github.com/postcss/postcss/issues/1509#issuecomment-772097567
Basé la respuesta en el error que aparece:
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }' - install 'path-browserify'