Skip to content

PhpStorm: Unresolved method or function setOutputPath() #151

@yhoiseth

Description

@yhoiseth

Thanks for making Encore.

I've done the following:

  1. Installed Encore as documented.
  2. Enabled the Node.js core library in PhpStorm.
  3. Restarted PhpStorm just to be sure.

In webpack.config.js, PhpStorm is showing the warning "Unresolved method or function setOutputPath()":
screen shot 2017-09-03 at 12 39 52

I've verified that setOutputPath() exists in node_modules/@symfony/webpack-encore/index.js.

How can I tell PhpStorm where to find the Encore functions?

Activity

Lyrkan

Lyrkan commented on Sep 3, 2017

@Lyrkan
Collaborator

It looks like it's related to PhpStorm not being able to handle the fact that a Proxy is exported:

2017-09-03_16-36-12

2017-09-03_16-37-00

I'm not sure how to solve that.

Edit: Note that this is only an IDE issue, Encore should be working as intended

weaverryan

weaverryan commented on Oct 12, 2017

@weaverryan
Member

I've also noticed this (I use PhpStorm). Can we add some custom JS doc to the exported Proxy to hint to the IDE about the methods? We could even possibly auto-generate these docs.

Lyrkan

Lyrkan commented on Nov 7, 2017

@Lyrkan
Collaborator

Doing something like that seems to actually work:

class Encore {
    /**
     * @returns {Encore}
     */
    method1() {
        // (...)
        return this;
    }

    /**
     * @param {string} test
     * @returns {Encore}
     */
    method2(test) {
        // (...)
        return this;
    }

    /**
     * @param {string} test
     * @returns {void}
     */
    method3(test) {
        // (...)
    }
}

/**
 * @type {Encore}
 */
module.exports = new Proxy(
    new API(),
    { /* ... */ }
);

So we'd need to:

  • switch the current const to a class (I tried to keep the const but for some reason that implied adding a @property tag for each method of the API)
  • replace all @return {exports}/@returns {exports} by @returns {Encore}
  • add the @type tag to the module.exports and instantiate the class
weaverryan

weaverryan commented on Nov 15, 2017

@weaverryan
Member

That sounds great! Nice find!

I had just started to look into https://github.com/DefinitelyTyped/DefinitelyTyped - i.e. you can create a typescript definition (https://www.npmjs.com/package/@types/webpack) and as soon as it's present, your editor uses it for auto-completion. Pretty cool... but it seems that your solution will work perfectly and is quite simple.

florentdestremau

florentdestremau commented on Feb 8, 2018

@florentdestremau
Contributor

Hi, is there any update on this issue? I could try but I'm not node expert, so not sure if it would be of any help at all. @Lyrkan the steps you mentioned, are they still valid ? I could try and do something 🙂

weaverryan

weaverryan commented on Feb 11, 2018

@weaverryan
Member

Do it! I’m sure those steps are still valid - so this is just a chore we need to get done :)

added a commit that references this issue on Feb 12, 2018
Lyrkan

Lyrkan commented on Feb 12, 2018

@Lyrkan
Collaborator

Fixed by #263 (make sure your PhpStorm is configured to use ES6 and not ES5), thank you @florentdestremau :)

gaea44

gaea44 commented on Apr 3, 2018

@gaea44

I also get this error, but only on one of my two projects.

In my first project (symfony 3 without flex), setOutputPath is correctly resolved.
In my second project (symfony 4 with flex), setOutputPath is unresolved.

I checked both of my projects and noticed that when I install Encore only with npm (or yarn) i get the 0.19.0 version.

But if I install it with flex, I get the 0.17.0 version, and if I forced it to the 0.1.9.0 in my packages.js, the issue is solved.

Hope it helps others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugBug Fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @weaverryan@Lyrkan@florentdestremau@gaea44@yhoiseth

        Issue actions

          PhpStorm: Unresolved method or function setOutputPath() · Issue #151 · symfony/webpack-encore