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

Configure node resolver #506

Closed
misteral opened this issue Aug 22, 2016 · 10 comments
Closed

Configure node resolver #506

misteral opened this issue Aug 22, 2016 · 10 comments
Labels

Comments

@misteral
Copy link

misteral commented Aug 22, 2016

Please help. I am stuck with node resolver configuration.

Project folder structure as the same: https://github.com/szwacz/electron-boilerplate.

In simple words:
app folder include node_project folder and package.json file and static js files
src folder include dinamic js files with import modules.

Part of file example:

import $ from 'jquery';
import Guid from 'guid';
import jCanvas from 'jcanvas';

jCanvas($, window);

class Comment {
    constructor($canvas, x = 0, y = 0) {
        this.$canvas = $canvas;
... more

I get eslint errors with this file in src folder:

  1:1   error  'jquery' should be listed in the project's dependencies. Run 'npm i -S jquery' to add it    import/no-extraneous-dependencies
  1:15  error  Unable to resolve path to module 'jquery'                                                   import/no-unresolved
  2:1   error  'guid' should be listed in the project's dependencies. Run 'npm i -S guid' to add it        import/no-extraneous-dependencies
  2:18  error  Unable to resolve path to module 'guid'                                                     import/no-unresolved
  3:1   error  'jcanvas' should be listed in the project's dependencies. Run 'npm i -S jcanvas' to add it  import/no-extraneous-dependencies
  3:21  error  Unable to resolve path to module 'jcanvas'

How I can resolve import node packages like 'jquery' in src folder?

I try use this eslint config, but it not work:

module.exports = {
    "settings": {
        "import/core-modules": [ 'electron' ],
        "import/resolver:": {
            "node": {
                "paths": [
                    "./app"
                ],
                "moduleDirectory": [
                    "node_modules",
                    "./app/node_modules"
                ]
            },
        },
    },
    "env": {
        "browser": true,
        "es6": true,
        "node": true,
    },
    "extends": "airbnb",
    "parserOptions": {
        "sourceType": "module"
    },
    "rules": {
        "indent": [
            "error",
            4
        ],
        "linebreak-style": [
            "error",
            "unix"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "semi": [
            "error",
            "always"
        ]
    }
};

@benmosher
Copy link
Member

Have you npm installed?

@misteral
Copy link
Author

@benmosher yes, does not have the error if I copy file into app folder.

@benmosher
Copy link
Member

Where is your eslintrc?

@misteral
Copy link
Author

@benmosher eslintrc is above.

@benmosher
Copy link
Member

Well, for one thing, nested package.jsons aren't currently supported for no-extraneous-dependencies, see #458 for tracking/details.

As for resolving modules in ./app/node_modules, I think you might need

            "node": {
                "paths": [
                    "./app",
                    "./app/node_modules"
                ],
                "moduleDirectory": [
                    "node_modules"
                ]
            },
        },

as your import/resolver config, but I'm not sure.

@misteral
Copy link
Author

@benmosher thanks for answer, but I got same errors:

$ eslint src/desky/Comment.js
The react/require-extension rule is deprecated. Please use the import/extensions rule from eslint-plugin-import instead.

/data/desky-for-gitlab/src/desky/Comment.js
  1:1   error  'jquery' should be listed in the project's dependencies. Run 'npm i -S jquery' to add it    import/no-extraneous-dependencies
  1:15  error  Unable to resolve path to module 'jquery'                                                   import/no-unresolved
  2:1   error  'guid' should be listed in the project's dependencies. Run 'npm i -S guid' to add it        import/no-extraneous-dependencies
  2:18  error  Unable to resolve path to module 'guid'                                                     import/no-unresolved
  3:1   error  'jcanvas' should be listed in the project's dependencies. Run 'npm i -S jcanvas' to add it  import/no-extraneous-dependencies
  3:21  error  Unable to resolve path to module 'jcanvas'                                                  import/no-unresolved

current eslintrc.js config:

module.exports = {
    "settings": {
        "import/core-modules": [ 'electron' ],
        "import/resolver:": {
            "node": {
                "paths": [
                    "./app",
                    "./app/node_modules"
                ],
                "moduleDirectory": [
                    "node_modules"
                ]
            },
        },
    },
    "env": {
        "browser": true,
        "es6": true,
        "node": true,
    },
    "extends": "airbnb",
    "parserOptions": {
        "sourceType": "module"
    },
    "rules": {
        "indent": [
            "error",
            4
        ],
        "linebreak-style": [
            "error",
            "unix"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "semi": [
            "error",
            "always"
        ]
    }
};

@toomuchdesign
Copy link

Any update about this issue?

@misteral
Copy link
Author

@toomuchdesign thank you. I think we can close issue.

@binarymist
Copy link

It's still an issue.

@ljharb
Copy link
Member

ljharb commented Jul 4, 2018

@binarymist then please file a new issue with repro steps

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

No branches or pull requests

5 participants