rehypejs / rehype-minify

plugins to minify HTML
https://unifiedjs.com
MIT License
90 stars 16 forks source link

Error: Cannot find module "." with webpack in a react app #22

Closed Mayeu closed 6 years ago

Mayeu commented 6 years ago

Hello :wave:

I'm trying to use rehype-minify in an app created with the default React creation CLI, and when I add

import rehypeMinify from "rehype-preset-minify";

I get the following error:

Error: Cannot find module "."

> 1 | import unified from "unified";
  2 | import rehypeStringify from "rehype-stringify";
  3 | import parseMarkdown from "remark-parse";
  4 | import remark2rehype from "remark-rehype";

If I remove the import of minify the compilation works without issue.

It seems it could be related to this issue about dynamically required modules.

Here are both stacktrace of the page:

Stack trace 1

webpackMissingModule
node_modules/uglify-js/tools/node.js:18
./node_modules/uglify-js/tools/node.js/UglifyJS.FILES<
node_modules/uglify-js/tools/node.js:18
./node_modules/uglify-js/tools/node.js
node_modules/uglify-js/tools/node.js:4
__webpack_require__
/home/m/documents/Projx_oknote/code/webpack/bootstrap a5394371802dc666947f:678
fn
/home/m/documents/Projx_oknote/code/webpack/bootstrap a5394371802dc666947f:88
./node_modules/rehype-minify-event-handler/index.js
node_modules/rehype-minify-event-handler/index.js:10
__webpack_require__
/home/m/documents/Projx_oknote/code/webpack/bootstrap a5394371802dc666947f:678
fn
/home/m/documents/Projx_oknote/code/webpack/bootstrap a5394371802dc666947f:88
./node_modules/rehype-preset-minify/index.js
node_modules/rehype-preset-minify/index.js:22
__webpack_require__
/home/m/documents/Projx_oknote/code/webpack/bootstrap a5394371802dc666947f:678
fn
/home/m/documents/Projx_oknote/code/webpack/bootstrap a5394371802dc666947f:88
Stack trace 2

webpackMissingModule
node_modules/uglify-js/tools/node.js:18
./node_modules/uglify-js/tools/node.js/UglifyJS.FILES<
node_modules/uglify-js/tools/node.js:18
./node_modules/uglify-js/tools/node.js
node_modules/uglify-js/tools/node.js:4
__webpack_require__
/home/m/documents/Projx_oknote/code/webpack/bootstrap a5394371802dc666947f:678
fn
/home/m/documents/Projx_oknote/code/webpack/bootstrap a5394371802dc666947f:88
./node_modules/rehype-minify-event-handler/index.js
node_modules/rehype-minify-event-handler/index.js:10
__webpack_require__
/home/m/documents/Projx_oknote/code/webpack/bootstrap a5394371802dc666947f:678
fn
/home/m/documents/Projx_oknote/code/webpack/bootstrap a5394371802dc666947f:88
./node_modules/rehype-preset-minify/index.js
node_modules/rehype-preset-minify/index.js:22
__webpack_require__
/home/m/documents/Projx_oknote/code/webpack/bootstrap a5394371802dc666947f:678
fn
/home/m/documents/Projx_oknote/code/webpack/bootstrap a5394371802dc666947f:88

I am not 100% sure of what the issue is, and where I could look for this dynamically inserted module (if it is the issue).

Any clue?

Mayeu commented 6 years ago

OK after more research it seems to be an issue with the fact that Uglyfy is basically not packageable via webpack. In one ticket they propose to use the "embedable" version of Uglify, but then you lose all the advantage of package management.

How would one go to embed Uglify in rehype-minify?

wooorm commented 6 years ago

Hmm, I’d suggest picking the rules you want and using that instead of the whole preset?

Mayeu commented 6 years ago

Thank you for your response, I'll try your suggestion.

I think we can close this since the issue is not part of rehype-minify but really ot Uglyfy not being packable.