dylang / npm-check

Check for outdated, incorrect, and unused dependencies.
https://www.npmjs.com/package/npm-check
MIT License
6.58k stars 239 forks source link

Npm-check 5.1 is too zealous while looking for missing modules #123

Open ingro opened 8 years ago

ingro commented 8 years ago

Hello! First of all, thanks for your work, I love this helper as I love to keep my projects with depencies up to date!

Anyway since updating to 5.1 I noticed an annoying behaviour: npm-check is starting to look for modules everywhere, even in .eslintrc or karma.conf.js!

The worst part is that I use webpack resolve's modulesDirectories options to load my modules with absolute paths from the root of my project, so I have a lot of this calls:

import Header from 'components/header' or import * as api from 'utils/api'

Before 5.1 they were ignored, while now they are all caught making the report unreadable:

actions                             �  MISSING!  Not installed.
                                        �  PKG ERR!  Not in the package.json. Found in: \src\scripts\actio
ns\animations.js, \src\scripts\actions\blocks.js, \src\scripts\actions\currentConversation.js, \src\script
s\actions\mail.js, \src\scripts\components\Main.jsx...

and so on.

I tried also with the -s flag but it skips a lot of modules so it's not viable either.

lijunle commented 8 years ago

Hi, @ingro

Why import * as api from 'utils/api' not import * as api from './utils/api'? (The ./ difference)

dylang commented 8 years ago

Thanks for this feedback @ingro.

-s skips this check, but it will still check all modules for what's out of date.

@lijunle can you make it so depcheck hands either use case?

ingro commented 8 years ago

@lijunle that's because I'm using webpack, so I can define many root paths for my modules, and I can include them with an absolute path instead of relatives

lijunle commented 8 years ago

It seems that your usage is same as this one: https://github.com/depcheck/depcheck/issues/132

@ingro Could you share your webpack configuration file?

ingro commented 8 years ago

Sure, here it is:

var config = {
    debug: true,
    devtool: 'cheap-source-map',
    entry: {
        bundle: ['./src/scripts/index', 'webpack-hot-middleware/client?timeout=5000']
    },
    output: {
        path: path.join(__dirname, 'public', 'dist', 'scripts'),
        filename: '[name].js',
        publicPath: '/dev/scripts/'
    },
    plugins: [
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery'
        }),
        new webpack.optimize.OccurenceOrderPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin(),
        new webpack.DefinePlugin({
            __DEVTOOLS__: !!process.env.DEBUG,
            'process.env': {
                'NODE_ENV': JSON.stringify(process.env.NODE_ENV)
            }
        })
    ],
    resolve: {
        modulesDirectories: ['node_modules', 'src/scripts'],
        extensions: ['', '.js', '.jsx']
    },
    module: {
        loaders: [{
            test: /\.js(x?)$/,
            loader: 'babel',
            exclude: /node_modules/,
            query: {
                plugins: ['transform-runtime']
            }
        }, {
            test: /nunjucks\.js/,
            loader: 'exports?nunjucks'
        }, {
            test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
            loader: 'url-loader?limit=10000&minetype=application/font-woff'
        }, {
            test: /\.(ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
            loader: 'file-loader'
        }, {
            test: /\.(png|svg|jpg)$/,
            loader: 'file-loader'
        }],
        noParse: [/sweetalert.min.js/]
    },
    watch: true
};
chadams commented 8 years ago

same issue here.

core 😟 MISSING! Not installed. 😟 PKG ERR! Not in the package.json. Found in: /app/src/core/actions/SystemActions.js

SystemActions.js liiks like this

import api from 'core/services/ExpApi';

also using webpack

matt328 commented 8 years ago

+1 for it being a little overzealous. It now is flagging every one of my require() statements, even though I'm requiring a module defined within my project. It flags all different sorts, './file', '../../file', 'file'.

jharris4 commented 8 years ago

I just started noticing that my webpack requires are getting flagged as non existent, like the following error:

Registry error Package!!script!mochadoesn't exist

lijunle commented 8 years ago

@jharris4 What does the error come from? Related to npm-check?

jharris4 commented 8 years ago

Yes, the error shows when I run npm-check from the terminal.

It is caused by this line in one of my source files:

require('!!script!mocha/mocha.js');

The documentation for this syntax can be found here: https://webpack.github.io/docs/loaders.html

alexkuz commented 7 years ago

I have similar problems:

resolve: {
        modules: [
          'web_modules',
          'node_modules',
          'shared'
        ]
}

I guess it's not that easy to support this, though (in this example, it would require checking every nested shared folder in project).

ramusus commented 6 years ago

The same here, when using webpack aliases:

    resolve: {
        modules: ['node_modules', 'bower_components'],
        descriptionFiles: ['package.json'],
        extensions: ['.js', '.jsx'],
        alias: {
            libs: path.join(__dirname, 'assets/libs'),
            tests: path.join(__dirname, 'assets/tests'),
            stores: path.join(__dirname, 'assets/stores'),
            components: path.join(__dirname, 'assets/components'),
        },
    },