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, plugin load hook should return a string. #15

Closed
trusktr opened this issue Jan 13, 2018 · 7 comments · Fixed by #16
Closed

Error, plugin load hook should return a string. #15

trusktr opened this issue Jan 13, 2018 · 7 comments · Fixed by #16

Comments

@trusktr
Copy link

trusktr commented Jan 13, 2018

I'm getting:

ERROR in ./src/index.js
Module build failed: Error: Error loading node_modules/core-js/library/modules/es6.object.to-string.js: plugin load hook should return a string, a {
code, map } object, or nothing/null
    at error (/home/trusktr/Downloads/src/trusktr+infamous/node_modules/rollup/dist/rollup.js:170:15)
    at /home/trusktr/Downloads/src/trusktr+infamous/node_modules/rollup/dist/rollup.js:18742:13
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

My config looks like this:

const path = require('path')
const babelConfig = require('./babel.config')
const bubleConfig = require('./buble.config')
const rollupConfig = require('./rollup.config.js')
const BabelMinify = require("babel-minify-webpack-plugin");

module.exports = {
    entry: './src/index.js',
    output: {
        path: __dirname,
        filename: 'global.js',
        library: 'infamous',
        libraryTarget: 'var', // alternative: "window"
    },
    module: {
        rules: [
            {
                test: /src\/index\.js$/,
                use: [{
                    loader: 'webpack-rollup-loader',
                    options: rollupConfig,
                }],
            },
            {
                test: /\.js$/,
                include: [
                    path.resolve(__dirname, 'src'),
                    path.resolve(__dirname, 'node_modules', '@awaitbox'), // ES6+
                    path.resolve(__dirname, 'node_modules', 'custom-attributes'), // ES6+
                ],
                use: [
                    {
                        loader: 'buble-loader',
                        options: bubleConfig,
                    },
                    {
                        loader: 'babel-loader',
                        options: Object.assign(babelConfig, {
                            //runtimeHelpers: true, // TODO: this is rollup plugin option. What's equivalent in babel-loader?
                        }),
                    },
                ],
            },
        ],
    },
    plugins: [
        new BabelMinify({}, {
            comments: false,
        })
    ],
}

where rollupConfig is this:

const commonjs    = require('rollup-plugin-commonjs')

module.exports = {
    input: 'src/index.js',
    output: {
        name: 'infamous',
        file: 'global.js',
        format: 'iife',
    },
    plugins: [
        commonjs({
            exclude: [ 'src/**' ],
            include: [ 'node_modules/**' ],
        }),
    ]
};

Any ideas what it might be? I thought about putting commonjs rollup plugin because I need to import from node_modules, and they aren't all ES6 Modules.

@trusktr
Copy link
Author

trusktr commented Jan 13, 2018

Ah, it's because node_modules/core-js/library/modules/es6.object.to-string.js is an empty file. Placing the word undefined inside of it fixes the problem. It all works!

@trusktr
Copy link
Author

trusktr commented Jan 13, 2018

Ah, crap. Well, the same node_modules that were missing when using Rollup directly, are now still missing.

Screw it, I'm not using Rollup. I will live with Webpack's heavier output because..... it just works!

@frontendphil
Copy link

I don't have any further insights, but am facing the same error. We are consuming some library code that has empty index.js files (mostly these included flowtype annotations that were stripped by the transpiler, thus the empty file).

I'd still be happy to get the setup working with this loader, because we're currently creating a 2.8mb bundle to display a form, which is not great at all. However, I don't have a clue where to start looking for a solution.

@erikdesjardins
Copy link
Owner

Ah, I've actually encountered this problem before. With the exact same core-js file too. Why did I never fix it...

I believe this is a bug in rollup itself; it tests the string for truthiness, so an empty string breaks it. I'll PR a fix. If it turns out that's intended, I'll add source || ' ' to this.

(But yes, this is very much a hack. I should make that clear in the readme.)

@erikdesjardins
Copy link
Owner

rollup/rollup#1908

@erikdesjardins
Copy link
Owner

(sorry about the delay, btw)

@erikdesjardins
Copy link
Owner

erikdesjardins commented Jan 26, 2018

rollup 0.55.1 has the fix.

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

Successfully merging a pull request may close this issue.

3 participants