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

Error: Package exports for 'D:\development\project\node_modules\terser' do not define a valid './package.json' target #299

Closed
jerptrs opened this issue Aug 19, 2020 · 12 comments

Comments

@jerptrs
Copy link

jerptrs commented Aug 19, 2020

  • Operating System: Win 10
  • Node Version: 13.1.0
  • NPM Version: 6.12.1
  • webpack Version: 4.44.1
  • terser-webpack-plugin Version: 4.1.0

Expected Behavior

Run without error and minify my Javascript code.

Actual Behavior

When running webpack it throws the following error:
Error: Package exports for 'D:\development\project\node_modules\terser' do not define a valid './package.json' target

Code

'use strict';
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const {
    CleanWebpackPlugin
} = require('clean-webpack-plugin');
const TerserWebpackPlugin = require('terser-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = (env, argv) => {
    const isProduction = (argv.mode === 'production');

    const config = {
        context: path.resolve(__dirname, 'src'),

        devServer: {
            publicPath: '/dist/',
            watchContentBase: true,
        },

        entry: [
            './js/app.js',
            './scss/main.scss',
        ],

        devtool: 'inline-surce-map',

        output: {
            filename: 'js/app.js',
            path: path.resolve(__dirname, 'dist'),
            publicPath: '../'
        },

        plugins: [
            new MiniCssExtractPlugin({
                filename: 'css/main.css',
            }),

            new CopyWebpackPlugin({
                patterns: [{
                    from: 'static',
                    to: 'static',
                }],
            }),

            new webpack.ProvidePlugin({
                $: 'jquery',
                jQuery: 'jquery',
                jquery: 'jquery',
                'window.jQuery': 'jquery',
                Popper: ['popper.js', 'default'],
            }),
        ],

        optimization: {
            minimizer: [
                new OptimizeCssAssetsPlugin(),
                new TerserWebpackPlugin(),
            ],
        },

        module: {
            rules: [{
                test: /\.scss$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                    'sass-loader',
                ],
            }],
        },
    };

    if (isProduction) {
        config.plugins.push(
            new CleanWebpackPlugin(),
        );
    }
    return config;
};

dependencies

  "devDependencies": {
    "clean-webpack-plugin": "^3.0.0",
    "copy-webpack-plugin": "^6.0.3",
    "css-loader": "^4.2.1",
    "mini-css-extract-plugin": "^0.10.0",
    "node-sass": "^4.14.1",
    "optimize-css-assets-webpack-plugin": "^5.0.3",
    "sass-loader": "^9.0.3",
    "style-loader": "^1.2.1",
    "terser-webpack-plugin": "^4.1.0",
    "webpack": "^4.44.1",
    "webpack-cli": "^3.3.12",
    "webpack-dev-server": "^3.11.0"
  },
  "dependencies": {
    "bootstrap": "^4.5.2",
    "jquery": "^3.5.1",
    "material-design-icons": "^3.0.1",
    "popper.js": "^1.16.1"
  }

How Do We Reproduce?

https://github.com/jerptrs/romman.hamburg
Clone and run npm run build

@alexander-akait
Copy link
Member

It looks like you just deleted our lovely crafted issue template. It was there for good reasons. Please help us solving your issue by answering the questions asked in this template. I'm closing this. Please either update the issue with the template and reopen, or open a new issue.

Fill out all fields, I can't help you without information.

@jerptrs
Copy link
Author

jerptrs commented Aug 19, 2020

@evilebottnawi whoops 😱 yea you are right, sorry about that 😞✊

I restarted VSCode and ran npm remove + npm install, seems to have fixed my issue 😎👍

@jerptrs
Copy link
Author

jerptrs commented Aug 19, 2020

Update:
I forgot that I used an older version (1.4.3) of the package for testing purpse, which worked fine.

I have added the repository where I'm having the issue.

@jerptrs
Copy link
Author

jerptrs commented Aug 19, 2020

@evilebottnawi sorry for pinging you again but could you take a look at the following code? Feeling pretty dumb right now because I can't figure my issue out.

webpack.config.js

'use strict';
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
    context: path.resolve(__dirname, 'src'),

    entry: [
        './app.js'
    ],

    output: {
        filename: '/app.js',
        path: path.resolve(__dirname, 'dist'),
        publicPath: '../'
    },

    optimization: {
        minimize: true,
        minimizer: [new TerserPlugin()],
    },
}

package.json

{
  "devDependencies": {
    "terser-webpack-plugin": "^4.1.0",
    "webpack": "^4.44.1",
    "webpack-cli": "^3.3.12"
  },
  "scripts": {
    "test": "webpack"
  }

src/app.js

console.log('test');

full error:

Error: Package exports for 'D:\development\terser-issue\node_modules\terser' do not define a valid './package.json' target
    at resolveExportsTarget (internal/modules/cjs/loader.js:545:13)
    at applyExports (internal/modules/cjs/loader.js:459:14)
    at resolveExports (internal/modules/cjs/loader.js:508:12)
    at Function.Module._findPath (internal/modules/cjs/loader.js:577:20)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:879:27)
    at Function.Module._load (internal/modules/cjs/loader.js:785:27)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (D:\development\terser-issue\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
    at Object.<anonymous> (D:\development\terser-issue\node_modules\terser-webpack-plugin\dist\index.js:24:39)
    at Module._compile (D:\development\terser-issue\node_modules\v8-compile-cache\v8-compile-cache.js:194:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
    at Module.load (internal/modules/cjs/loader.js:914:32)
    at Function.Module._load (internal/modules/cjs/loader.js:822:14)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (D:\development\terser-issue\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
    at Object.<anonymous> (D:\development\terser-issue\node_modules\terser-webpack-plugin\dist\cjs.js:3:16)
    at Module._compile (D:\development\terser-issue\node_modules\v8-compile-cache\v8-compile-cache.js:194:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
    at Module.load (internal/modules/cjs/loader.js:914:32)
    at Function.Module._load (internal/modules/cjs/loader.js:822:14)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (D:\development\terser-issue\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
    at Object.<anonymous> (D:\development\terser-issue\webpack.config.js:4:22)
    at Module._compile (D:\development\terser-issue\node_modules\v8-compile-cache\v8-compile-cache.js:194:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
    at Module.load (internal/modules/cjs/loader.js:914:32)
    at Function.Module._load (internal/modules/cjs/loader.js:822:14)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (D:\development\terser-issue\node_modules\v8-compile-cache\v8-compile-cache.js:161:20)
    at WEBPACK_OPTIONS (D:\development\terser-issue\node_modules\webpack-cli\bin\utils\convert-argv.js:114:13) {
  code: 'MODULE_NOT_FOUND'
}

@alexander-akait
Copy link
Member

Something breaks node_modules, maybe you have corrupted node_modules directory or file system, maybe you hard disk is starting dead

@jerptrs
Copy link
Author

jerptrs commented Aug 19, 2020

Tried it on my HDD and SSD, on both I get the same error. Like I said, with version 1.4.3 of terser-webpack-plugin it works fine. I verified the cache, which came back with a healthy result and event deleted the cache and installed the packages new on both drives.

@alexander-akait
Copy link
Member

It is the problem from Node.js, we can't fix it on our side

@jerptrs
Copy link
Author

jerptrs commented Aug 19, 2020

It is the Node.js version. Tried it with 13.1.0 on three machines and always got the same error but works fine with the latest Node.js version 14.8.0. There should be a warning that the current version f terser-webpack-plugin does not work with Node v13.1.0.

@alexander-akait
Copy link
Member

Some version of Node.js can be broken, we can't list them all

@jerptrs
Copy link
Author

jerptrs commented Aug 20, 2020

Because you don't want to, am I right?

@alexander-akait
Copy link
Member

alexander-akait commented Aug 20, 2020

@jerptrs Don't want what? It is bug on node side nodejs/modules#446, I can't fix it here, listing all requires testing all versions on CLI, test will be slow, each PR will be cost a lot of time, do you have time on this? Node.js recommend using LTS version if you wanna be stable

@jerptrs
Copy link
Author

jerptrs commented Aug 20, 2020

Oh fml - thought 13.1.0 was an LTS version since I used NVM 🤷 I'm sorry 😞

Note to myself: thinking and then making a comment.

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

No branches or pull requests

2 participants