Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhpStorm: Unresolved method or function setOutputPath() #151

Closed
yhoiseth opened this issue Sep 3, 2017 · 8 comments
Closed

PhpStorm: Unresolved method or function setOutputPath() #151

yhoiseth opened this issue Sep 3, 2017 · 8 comments
Labels
Bug Bug Fix

Comments

@yhoiseth
Copy link

yhoiseth commented Sep 3, 2017

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?

@Lyrkan
Copy link
Collaborator

Lyrkan commented Sep 3, 2017

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
Copy link
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.

@weaverryan weaverryan added the Bug Bug Fix label Oct 12, 2017
@Lyrkan
Copy link
Collaborator

Lyrkan commented Nov 7, 2017

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
Copy link
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
Copy link
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
Copy link
Member

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

weaverryan added a commit that referenced this issue Feb 12, 2018
…orentdestremau)

This PR was squashed before being merged into the master branch (closes #263).

Discussion
----------

Updated Encore object to class for proxy typehinting

Hello, I'm trying to address #151 with this PR.

I have an error in my tests:

```
Public API
    setOutputPath
  Error: Encore.configureRuntimeEnvironment is not a recognized property or method.

  - index.js:942 Object.get
    /home/florent/dev/opensource/webpack-encore/index.js:942:27
  - index.js:17 Context.beforeEach
    /home/florent/dev/opensource/webpack-encore/test/index.js:17:13
  - runnable.js:348 callFn
    [webpack-encore]/[mocha]/lib/runnable.js:348:21
  - runnable.js:340 Hook.Runnable.run
    [webpack-encore]/[mocha]/lib/runnable.js:340:7
  - runner.js:309 next
    [webpack-encore]/[mocha]/lib/runner.js:309:10
  - runner.js:339 Immediate.<anonymous>
    [webpack-encore]/[mocha]/lib/runner.js:339:5
  - timers.js:789 runCallback
```

I'm looking into it but any advice would be welcome so that we all get a proper proxy and autocomplete on :heart: *PHPSTORM* :heart:

Commits
-------

fb7498d Initiated class in proxy, uniformized @returns
79dbee8 Updated Encore object to class for proxy typehinting
@Lyrkan
Copy link
Collaborator

Lyrkan commented Feb 12, 2018

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

@Lyrkan Lyrkan closed this as completed Feb 12, 2018
@gaea44
Copy link

gaea44 commented Apr 3, 2018

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
Labels
Bug Bug Fix
Projects
None yet
Development

No branches or pull requests

5 participants