odoo / owl

OWL: A web framework for structured, dynamic and maintainable applications
https://odoo.github.io/owl/
Other
1.1k stars 332 forks source link

Problem while using of useService #1583

Closed jujuna closed 4 months ago

jujuna commented 5 months ago

I am making web client from zero through tutorial of OXP but I have this error when I use useService Uncaught (in promise) Error: An error occured in the owl lifecycle (see this Error's "cause" property)

this is my assets code

    'assets': {
        'university_library.assets': [
            # bootstrap
            ('include', 'web._assets_helpers'),
            'web/static/src/scss/pre_variables.scss',
            'web/static/lib/bootstrap/scss/_variables.scss',
            ('include', 'web._assets_bootstrap_backend'),

            # required for fa icons
            'web/static/src/libs/fontawesome/css/font-awesome.css',

            # include base files from framework
            ('include', 'web._assets_core'),

            # remove some files that we do not use to create a minimal bundle
            # ('remove', 'web/static/src/core/**/*'),
            # ('remove', 'web/static/lib/luxon/luxon.js'),
            'web/static/src/core/utils/functions.js',
            'web/static/src/core/browser/browser.js',
            'web/static/src/core/registry.js',
            'web/static/src/core/assets.js',
            'university_library/static/src/**/*',
        ],
    },

and small js code



import {Component, useState} from "@odoo/owl";
import {useService} from "@web/core/utils/hooks";

// import {onWillStart, onWillRender, onMounted, onRendered, useRef} from "@odoo/owl";

export class Libraries extends Component {
    static template = 'university_library.Library'

    setup() {
        super.setup();
        this.orm = useService("orm");
    }

}
fdardenne commented 5 months ago

Hello 👋 ,

Your error message is quite generic and does not provide the full details of the error. Therefore, I cannot provide you with a precise solution. However, I believe that the error may be due to the fact that you need to start the services with await startServices(env); before mounting the Owl app. You can refer to an example of how I did this in a standalone app at https://github.com/fdardenne/owlybook/blob/main/static/src/js/main.js.

PS: you don't need to call super.setup() in the setup() method. The Component class does not implement any logic in this method.

I hope this helps!

flotho commented 5 months ago

hi @jujuna maybe the answer is ther https://github.com/odoo/owl/issues/1564

flotho commented 5 months ago

@jujuna which Odoo version are you working with ? I personnaly struggling on v16 https://github.com/odoo/odoo/issues/151490

jujuna commented 5 months ago

@fdardenne Hello, your link doesn't work

jujuna commented 5 months ago

@flotho I am working on 17 version, I will see your link if it helps me, thank you!

jujuna commented 5 months ago

@flotho @fdardenne This is my main.js file

/** @odoo-module **/

import { mount, whenReady } from "@odoo/owl";
import { WebClient } from "./webclient/web_client";
import { templates } from "@web/core/assets";

// Mount the WebClient component when the document.body is ready
whenReady(() => {
  mount(WebClient, document.body, {
    templates,
    dev: true,
    name: "Library",
  });
});
flotho commented 5 months ago

as recommended for v17, use mountcomponent instead, it will work easier

flotho commented 5 months ago

Hi @fdardenne does the code you shared woks with services ?

fdardenne commented 5 months ago

Hi @fdardenne does the code you shared woks with services ?

Hello, yes it should

flotho commented 5 months ago

I meant does your code effectively worked or did you expect it to work ?

jujuna commented 5 months ago

@flotho Thank you! I used mountComponent and it works.

flotho commented 5 months ago

is it a standalone component ?

jujuna commented 5 months ago

@flotho Yes

flotho commented 5 months ago

perfect, everything is clear. MAybe this issue could be closed ?