Sencha CMD: 404 errors when running built production version

我与影子孤独终老i 提交于 2019-12-04 18:13:31

Try to include all classes you need inside uses or requires section of your app.js.

Note, that if controller is requiring some views, you may omit that view in require section of app.js, since it will be included anyway when sencha tool will be parsing your controller.

Try to use full paths when adding files to uses/requires section of app.js. That is, write MyApp.controller.pages.Home or MyApp.store.users.List but now pages.Home or users.List.

You can use -before-build and -after-build Ant targets to modify your app.js just before sencha tool's YUI minimizer phase start.
In my case I ended up with searching for all controllers inside app/controller folder and adding their names to uses section of app.js. For it that was enough, since other needed classes were required from within my controllers.

In order to be able to find uses section of app.js, I've used special comment

/*ant-generated-content-start*/ /*ant-generated-content-end*/

My app.js

Ext.application({
    name: 'MyApp',
    appFolder: 'app',

    controllers: [
        "main.App"
    ],

    uses: [
        /*ant-generated-content-start*/ /*ant-generated-content-end*/
    ],
    autoCreateViewport: true,
});

My build.xml

<?xml version="1.0" encoding="utf-8"?>
<project name="MyApp" default=".help">
    <import file="${basedir}/.sencha/app/build-impl.xml"/>

    <target name="-before-build">

        <echo message="Collecting all controllers in application class property ... "/>
        <fileset id="app_controllers" dir="${app.dir}/app/controller" casesensitive="yes">
            <include name="**/*.js"/>
        </fileset>
        <pathconvert pathsep="," property="app_controller_names" refid="app_controllers" targetos="unix">
            <chainedmapper>
                <globmapper from="${app.dir}/app/*" to="${ant.project.name}/*" casesensitive="no" handledirsep="yes"/>
                <chainedmapper>
                    <regexpmapper from="^(.*)\.js$$" to='"\1"'/>
                    <filtermapper>
                        <replacestring from="/" to="."/>
                        <replacestring from="\" to="."/>
                    </filtermapper>
                </chainedmapper>
            </chainedmapper>
        </pathconvert>
        <echo message="Collected controllers: ${app_controller_names}"/>

        <echo message="Injecting into app.js ..."/>
        <replaceregexp file="${app.dir}/app/app.js"
                       match="/\*ant-generated-content-start\*/(.*)/\*ant-generated-content-end\*/"
                       replace="/*ant-generated-content-start*/ ${app_controller_names} /*ant-generated-content-end*/"
                       byline="true"
                />
    </target>

    <target name="-after-build">
        <echo message="Reverting to original app.js ..."/>
        <replaceregexp file="${app.dir}/app/app.js"
                       match="/\*ant-generated-content-start\*/(.*)/\*ant-generated-content-end\*/"
                       replace="/*ant-generated-content-start*/ /*ant-generated-content-end*/"
                       byline="true"
                />
    </target>

</project>
Joseph Victor Zammit

I still do not understand the problem fully but this is what I did to fix the issue.

I had two models; App.js and Window.js which had a hasMany and belongsTo relationship respectively. In App.js:

associations: [{
    type : 'hasMany',
    model: 'WD.model.Window',
    name : 'windows'
}]

while in Window.js I had:

associations: [{
    type : 'belongsTo',
    model: 'WD.model.App',
    associationKey: 'appId'
}]

I started to suspect these parts as causing the problem because they were the only ExtJS modules giving a 404; the other modules that give a 404 depend on the model files which use hasMany and belongsTo.

I simply removed the associations snippets pasted above (because right now I'm not using them as they don't really work, because I still have to load the data myself rather than children being loaded automagically). Then re-ran sencha app build, and the production version works properly!

If anyone (particularly someone from Sencha) knows exactly why my clumsy fix works, please answer the question or comment below, and I will update the answer.

Thanks @bhovhannes for your answer which still led to useful insight to the problem; +1ed.

I had equal problem too,, To solve this problem I just change the name of class. I built using SenchaCmd 3.1.xx and Sencha Touch 2.2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!