Google compilation process closing node_modules

I am trying to use google compiler as an alternative for webpack. I am currently using the following files to compile all the files inside my folder:

java -jar closure-compiler.jar --process_common_js_modules --js_output_file=static/out.js 'lib/js/src/frontend/*.js'"

The problem in one of these files requires React and ReactDOM. I get the following error:

lib/js/src/frontend/app.js:7: ERROR - Failed to load module "react"
var React    = require("react");
           ^^^^^^^^^^^^^^^^

lib/js/src/frontend/app.js:8: ERROR - Failed to load module "react-dom"
var ReactDom = require("react-dom");
           ^^^^^^^^^^^^^^^^^^^^

How do I make sure that the Google Closure compiler looks inside node_modules to find the appropriate third-party modules?

+4
source share
1 answer

Recent versions of Closure-Compiler modules support node.

- . , package.json , --js node_modules/react/package.json.

, , , , .

:

java -jar closure-compiler.jar --process_common_js_modules
    --dependency_mode=STRICT
    --module_resolution=NODE
    --entry_point="lib/js/src/frontend/app"
    --js_output_file=static/out.js
    --js='node_modules/react/package.json'
    --js='node_modules/react/**/*.js'
    --js='node_modules/react-dom/package.json'
    --js='node_modules/react-dom/**/*.js'
    --js='lib/js/src/frontend/*.js'

.

+3

Source: https://habr.com/ru/post/1667667/


All Articles