重命名或删除js文件,导致控制台报错

creator1.4.0 mac环境

项目中有一个被引用的UserInfo.js组件,开发过程中重命名,发现异常,于是恢复备份回来,把引用它的场景给删了,结果还是报同样的错误,切换到其他场景时,控制台报的全是切换的场景丢失所有引用的组件。项目不能再点运行预览按钮。

Compile error: Cannot require ‘UserInfo’ from ‘/Users/my/myproject/westar/temp/scripts/assets/script/setup’. Module not found.
at Readable. (/Applications/CocosCreator.app/Contents/Resources/app.asar/editor/page/compile-worker.js:1:3554)
at emitOne (events.js:96:13)
at Readable.emit (events.js:188:7)
at Labeled. (/Applications/CocosCreator.app/Contents/Resources/app.asar/node_modules/read-only-stream/index.js:28:44)
at emitOne (events.js:96:13)
at Labeled.emit (events.js:188:7)
at Labeled. (/Applications/CocosCreator.app/Contents/Resources/app.asar/node_modules/stream-splicer/index.js:130:18)
at emitOne (events.js:101:20)
at Labeled.emit (events.js:188:7)
at Deps. (/Applications/CocosCreator.app/Contents/Resources/app.asar/node_modules/stream-splicer/index.js:130:18)
at /Applications/CocosCreator.app/Contents/Resources/app.asar/editor/core/compiler.js:1:1022
at /Applications/CocosCreator.app/Contents/Resources/app.asar/editor/core/compiler.js:1:466
at BrowserWindow. (/Applications/CocosCreator.app/Contents/Resources/app.asar/editor/core/compiler.js:1:2045)
at BrowserWindow.g (events.js:286:16)
at emitOne (events.js:101:20)
at BrowserWindow.emit (events.js:188:7)

PS:新建的项目重命名或删除场景均没有发现以上异常。

原先项目曾尝试使用最新版本开发,发现太多问题,切换会1.4.0,还是不时有各种问题,希望不再有其他异常了:worried:

刚下载了1.4.1正式版,测试了一下,一重命名,立即报错,下面的报错跟1.4.0的应该是一模一样的了:

Compile error: Cannot require ‘UserInfo’ from ‘/Users/my/myproject/temp/scripts/assets/script/setup’. Module not found.
at Readable. (/Applications/CocosCreator.app/Contents/Resources/app.asar/editor/page/compile-worker.js:1:3554)
at emitOne (events.js:96:13)
at Readable.emit (events.js:188:7)
at Labeled. (/Applications/CocosCreator.app/Contents/Resources/app.asar/node_modules/read-only-stream/index.js:28:44)
at emitOne (events.js:96:13)
at Labeled.emit (events.js:188:7)
at Labeled. (/Applications/CocosCreator.app/Contents/Resources/app.asar/node_modules/stream-splicer/index.js:130:18)
at emitOne (events.js:101:20)
at Labeled.emit (events.js:188:7)
at Deps. (/Applications/CocosCreator.app/Contents/Resources/app.asar/node_modules/stream-splicer/index.js:130:18)
at /Applications/CocosCreator.app/Contents/Resources/app.asar/editor/core/compiler.js:1:1022
at /Applications/CocosCreator.app/Contents/Resources/app.asar/editor/core/compiler.js:1:466
at BrowserWindow. (/Applications/CocosCreator.app/Contents/Resources/app.asar/editor/core/compiler.js:1:2045)
at BrowserWindow.g (events.js:286:16)
at emitOne (events.js:101:20)
at BrowserWindow.emit (events.js:188:7)

把文件名重命名回原名又恢复正常

不想再测试了。。。就使用原来的名字吧

重命名或删除脚本后,当然会有这个报错啊,因为你其它脚本 require 了这个文件,所以就会报错说文件找不到了。

关于引用我也想过,引用关系已经去掉了,就是在场景中已经删除了该js文件的引用,还是一模一样的报错,我把删除引用后重命名的报错拷贝一下吧:
Compile error: Cannot require ‘UserInfo’ from ‘/Users/my/myproject/temp/scripts/assets/script/setup’. Module not found.
at Readable. (/Applications/CocosCreator.app/Contents/Resources/app.asar/editor/page/compile-worker.js:1:3554)
at emitOne (events.js:96:13)
at Readable.emit (events.js:188:7)
at Labeled. (/Applications/CocosCreator.app/Contents/Resources/app.asar/node_modules/read-only-stream/index.js:28:44)
at emitOne (events.js:96:13)
at Labeled.emit (events.js:188:7)
at Labeled. (/Applications/CocosCreator.app/Contents/Resources/app.asar/node_modules/stream-splicer/index.js:130:18)
at emitOne (events.js:101:20)
at Labeled.emit (events.js:188:7)
at Deps. (/Applications/CocosCreator.app/Contents/Resources/app.asar/node_modules/stream-splicer/index.js:130:18)
at /Applications/CocosCreator.app/Contents/Resources/app.asar/editor/core/compiler.js:1:1022
at /Applications/CocosCreator.app/Contents/Resources/app.asar/editor/core/compiler.js:1:466
at BrowserWindow. (/Applications/CocosCreator.app/Contents/Resources/app.asar/editor/core/compiler.js:1:2045)
at BrowserWindow.g (events.js:286:16)
at emitOne (events.js:101:20)
at BrowserWindow.emit (events.js:188:7)

上面提到删除场景,也是考虑到引用关系,就测试索性把整个引用它的场景删了,还是报同样的错误

这不是在场景中引用,是在脚本中的。你在其它的 js 脚本内,写了 require(‘UserInfo’),就会有这个报错。

果真有个脚本引用了,非常感谢!