cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
8.83k stars 2.05k forks source link

Custom Component Retrieval Issue in Build (getComponent returns null) #17898

Open tafedorov78 opened 5 days ago

tafedorov78 commented 5 days ago

Cocos Creator version

3.8.3

System information

chrome, macos, windows

Issue description

I’m experiencing an issue with a custom component attached to a node. When accessing the component locally using the getComponent method, it returns the expected component. However, when accessing the component remotely in a build from remote host, it returns null. in the attached project - look at PrizeController --> const switcher2 = node.getComponent('NodeSwitchComponent');

Relevant error log output

null

Steps to reproduce

  1. Attach a custom component to a node.
  2. Access the component locally using getComponent - the component is retrieved correctly.
  3. Access the component remotely (remote host!!!) in a build - getComponent returns null.

Minimal reproduction project

test.zip

longchuan commented 4 days ago

image look at this

longchuan commented 4 days ago

image Thanks for I got a gift program😂

tafedorov78 commented 4 days ago

I don't think you got it. I mentioned it should be run it remotely, not on your local machine that the point.

tafedorov78 commented 4 days ago

I found one thing - if I set a target in tsconfig = es6 it does not work!

longchuan commented 3 days ago

I don't think you got it. I mentioned it should be run it remotely, not on your local machine that the point.

A slowly network: http://119.3.232.55/web-mobile/index.html image

longchuan commented 3 days ago

The root path of import is the dir of script file.So,you should add "../" to return parent dir.