react19.0.0 仓库构建
运行指令 npm run build
报以下错误
panminxiang@Mac react % npm run build
> build
> node ./scripts/rollup/build-all-release-channels.js
BUILDING react.development.js (node_dev)
COMPLETE react.development.js (node_dev)
BUILDING react.production.js (node_prod)
OH NOES! react.production.js (node_prod)
-- PLUGIN_ERROR (scripts/rollup/plugins/closure-plugin) --
Error: java -jar /Users/panminxiang/Sites/Commonfiles/Github/react/node_modules/google-closure-compiler-java/compiler.jar --compilation_level=SIMPLE --language_in=ECMASCRIPT_2020 --language_out=ECMASCRIPT5_STRICT --emit_use_strict=true --env=CUSTOM --warning_level=QUIET --source_map_include_content=true --use_types_for_optimization=false --process_common_js_modules=false --rewrite_polyfills=false --inject_libraries=false --allow_dynamic_import=true --assume_function_wrapper=true --renaming=false --js=/var/folders/cs/w489x32x3hvfglcysqqq580m0000gn/T/tmp-4826Fd01F1kduh3u
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
at /Users/panminxiang/Sites/Commonfiles/Github/react/scripts/rollup/plugins/closure-plugin.js:16:16
at ChildProcess.<anonymous> (/Users/panminxiang/Sites/Commonfiles/Github/react/node_modules/google-closure-compiler/lib/node/closure-compiler.js:103:9)
at ChildProcess.emit (node:events:517:28)
at maybeClose (node:internal/child_process:1098:16)
at Socket.<anonymous> (node:internal/child_process:450:11)
at Socket.emit (node:events:517:28)
at Pipe.<anonymous> (node:net:350:12)
错误提示没有 java 命令启动 jar 包
瞅一眼 rollup/plugins/closure-plugin.js 文件
const ClosureCompiler = require('google-closure-compiler').compiler;
再瞅一眼 google-closure-compiler/lib/node/closure-compiler.js
Compiler.prototype.javaPath = 'java';
const compilerPath = require('google-closure-compiler-java');
let compileProcess = spawn(
this.javaPath,
this.commandArguments,
this.spawnOptions
);
去 google-closure-compiler-java.js 看最后一眼
module.exports = require.resolve('./compiler.jar');
大致确定想用 java 来处理 .jar 包
安装 java
搜出来的地址是:https://www.java.com/zh-CN/download/ (坑)
安装完成后,重新构建
报错:
panminxiang@Mac react % npm run build
> build
> node ./scripts/rollup/build-all-release-channels.js
BUILDING react.development.js (node_dev)
COMPLETE react.development.js (node_dev)
BUILDING react.production.js (node_prod)
OH NOES! react.production.js (node_prod)
-- PLUGIN_ERROR (scripts/rollup/plugins/closure-plugin) --
Error: java -jar /Users/panminxiang/Sites/Commonfiles/Github/react/node_modules/google-closure-compiler-java/compiler.jar --compilation_level=SIMPLE --language_in=ECMASCRIPT_2020 --language_out=ECMASCRIPT5_STRICT --emit_use_strict=true --env=CUSTOM --warning_level=QUIET --source_map_include_content=true --use_types_for_optimization=false --process_common_js_modules=false --rewrite_polyfills=false --inject_libraries=false --allow_dynamic_import=true --assume_function_wrapper=true --renaming=false --js=/var/folders/cs/w489x32x3hvfglcysqqq580m0000gn/T/tmp-76517zhLNrLkJEI7
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/google/javascript/jscomp/CommandLineRunner has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:359)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:635)
at /Users/panminxiang/Sites/Commonfiles/Github/react/scripts/rollup/plugins/closure-plugin.js:16:16
at ChildProcess.<anonymous> (/Users/panminxiang/Sites/Commonfiles/Github/react/node_modules/google-closure-compiler/lib/node/closure-compiler.js:103:9)
at ChildProcess.emit (node:events:517:28)
at maybeClose (node:internal/child_process:1098:16)
at Socket.<anonymous> (node:internal/child_process:450:11)
at Socket.emit (node:events:517:28)
at Pipe.<anonymous> (node:net:350:12)
意思是 google-closure-compiler-java jar 包是 jdk55 编译的,我的 JRE 处理不了,版本太低了。而且中文官网只给了 JRE,没给 JDK。
上面官网是 java 面向普通用户,去开发者官网下载 java
https://www.oracle.com/java/technologies/downloads/#jdk22-mac
选择 dmg 文件后,覆盖安装
panminxiang@Mac react % /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
22.0.1 (arm64) "Oracle Corporation" - "Java SE 22.0.1" /Library/Java/JavaVirtualMachines/jdk-22.jdk/Contents/Home
1.8.411.09 (arm64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-22.jdk/Contents/Home
有 jdk 信息了
重新构建
panminxiang@Mac react % npm run build
> build
> node ./scripts/rollup/build-all-release-channels.js
BUILDING react.development.js (node_dev)
COMPLETE react.development.js (node_dev)
BUILDING react.production.js (node_prod)
COMPLETE react.production.js (node_prod)
BUILDING React-dev.js (fb_www_dev)
COMPLETE React-dev.js (fb_www_dev)
BUILDING React-prod.js (fb_www_prod)
COMPLETE React-prod.js (fb_www_prod)
BUILDING React-profiling.js (fb_www_profiling)
COMPLETE React-profiling.js (fb_www_profiling)
....
─────────────────────────────────────────────────────────────────────────────┬───────────┬──────────────┬──────┬───────────┬──────────────┬──────┐
│ Bundle │ Prev Size │ Current Size │ Diff │ Prev Gzip │ Current Gzip │ Diff │
├─────────────────────────────────────────────────────────────────────────────┼───────────┼──────────────┼──────┼───────────┼──────────────┼──────┤
│ react.development.js (NODE_DEV) │ 0 B │ 91.23 KB │ n/a │ 0 B │ 25.02 KB │ n/a │
├─────────────────────────────────────────────────────────────────────────────┼───────────┼──────────────┼──────┼───────────┼──────────────┼──────┤
│ react.production.js (NODE_PROD) │ 0 B │ 16.48 KB │ n/a │ 0 B │ 4.29 KB │ n/a │
├─────────────────────────────────────────────────────────────────────────────┼───────────┼──────────────┼──────┼───────────┼──────────────┼──────┤
│ React-dev.js (FB_WWW_DEV) │ 0 B │ 113.37 KB │ n/a │ 0 B │ 29.4 KB │ n/a │
├─────────────────────────────────────────────────────────────────────────────┼───────────┼──────────────┼──────┼───────────┼──────────────┼──────┤
│ React-prod.js (FB_WWW_PROD) │ 0 B │ 22.55 KB │ n/a │ 0 B │ 5.78 KB │ n/a │
├─────────────────────────────────────────────────────────────────────────────┼───────────┼──────────────┼──────┼───────────┼──────────────┼──────┤
│ React-profiling.js (FB_WWW_PROFILING) │ 0 B │ 22.97 KB │ n/a │ 0 B │ 5.85 KB │ n/a │
├─────────────────────────────────────────────────────────────────────────────┼───────────┼──────────────┼──────┼───────────┼──────────────┼──────┤
│ React-dev.js (RN_FB_DEV) │ 0 B │ 101.8 KB │ n/a │ 0 B │ 27.34 KB │ n/a │
├─────────────────────────────────────────────────────────────────────────────┼───────────┼──────────────┼──────┼───────────┼──────────────┼──────┤
│ React-prod.js (RN_FB_PROD) │ 0 B │ 19.19 KB │ n/a │ 0 B │ 4.98 KB │ n/a │
├─────────────────────────────────────────────────────────────────────────────┼───────────┼──────────────┼──────┼───────────┼──────────────┼──────┤
│ React-profiling.js (RN_FB_PROFILING) │ 0 B │ 19.61 KB │ n/a │ 0 B │ 5.05 KB │ n/a │
...
下面就可以构建 react devtools 插件了
我只想用下 react devtools 就这么难么