-
Creator 版本: 3.8.1
-
目标平台: Chrome浏览器
-
重现方式:
在组件文件中引入@vue/reactivity的ref并使用
// GameManager.ts
import { ref } from "@vue/reactivity";
// ...
@ccclass("GameManager")
export class GameManager extends Component {
test() {
console.log("ref", ref);
}
protected async onLoad() {
this.test();
}
// ...
}
- 首个报错:
ReferenceError: process is not defined
at _cjsLoader.define../dist/reactivity.cjs.prod.js (index.js:12:2)
at CjsLoader._load (cjs-loader.mjs:78:9)
at CjsLoader._tryModuleLoad (cjs-loader.mjs:63:18)
at CjsLoader._require (cjs-loader.mjs:42:14)
at CjsLoader.require (cjs-loader.mjs:27:21)
at Object.execute (index.mjs:7:8)
at doExec (system-core.js:309:30)
at postOrderExec (system-core.js:300:21)
at system-core.js:285:28
at Array.forEach (<anonymous>)
(anonymous) @ index.js:1
(anonymous) @ index.js:1
(anonymous) @ index.js:1
c @ index.js:1
点击报错信息定位到的相关代码:
if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/reactivity.cjs.prod.js')
} else {
module.exports = require('./dist/reactivity.cjs.js')
}
如果修改导入语句为import具体的文件:
import { ref } from "@vue/reactivity/dist/reactivity.esm-browser.js";
则报错为
Error: Error: Unexpected export statement in CJS module.
at :7456/@:1268:8
at Object.execute (data:text/javascript,%0A%2F%2F%20This%20module%20is%20auto-generated%20to%20report%20error%20emitted%20when%20try%20to%20load%20module%20file%3A%2F%2F%2FC%3A%2FWork%2FPorjects%2Fmahjong-matching-game%2Fnode_modules%2F%40vue%2Freactivity%2Fdist%2Freactivity.esm-browser.js%20at%20runtime.%0Athrow%20new%20Error(%60Error%3A%20Unexpected%20export%20statement%20in%20CJS%20module.%0A%20%20at%20%40%3A1268%3A8%60)%3B%0A%20%20%20%20%20%20%20%20:3:7)
at doExec (system-core.js:309:30)
at postOrderExec (system-core.js:300:21)
at system-core.js:285:28
at Array.forEach (<anonymous>)
at postOrderExec (system-core.js:283:10)
at system-core.js:285:28
at Array.forEach (<anonymous>)
at postOrderExec (system-core.js:283:10)
at system-core.js:285:28
(anonymous) @ index.js:1
(anonymous) @ index.js:1
(anonymous) @ index.js:1
c @ index.js:1
在HTML文件中这样导入时无报错:
<script type="module">
import { ref } from './node_modules/@vue/reactivity/dist/reactivity.esm-browser.js';
console.log('ref', ref);
</script>


