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: Module build failed: Error [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string without null bytes. Received type string #12

Open
budarin opened this issue Apr 20, 2018 · 3 comments

Comments

@budarin
Copy link

budarin commented Apr 20, 2018

Hi!

I have a problem with the loader in my project.
Webpack 4.6.0
Here is loaders config fo image loader:

            {
                test: /\.(svg|png|jpg|gif)$/,
                include: path.resolve('./src'),
                exclude: path.resolve('node_modules'),
                use: {
                    loader: 'image-size',
                    options: {
                        name: 'img/[name].[hash:7].[ext]',
                    },
                },
            }

Using an image in my code:

import Img from '../../assets/404.png';

trying to run webpack and got an error:

ERROR in ./src/common/assets/404.png
Module build failed: Error [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string without null bytes. Received type string
    at nullCheck (fs.js:177:16)
    at Object.fs.openSync (fs.js:659:3)
    at syncFileToBuffer (...\node_modules\image-size\lib\index.js:58:23)
    at Object.module.exports (...\node_modules\image-size\lib\index.js:100:18)

tryied to guess what is happening - I've put console log into loader

/**
 * @params input - buffer or relative/absolute path of the image file
 * @params callback - optional function for async detection
 */
module.exports = function (input, callback) {

    console.log('typeof input', typeof input, input);

and got in console:

IHDR   �   �   �"�f   �sRGB ����   �gAMA  ����a�   	pHYs  ��  ����o�d  ylIDATx^�]�`����ݽ�^H�	IH���k�E�`��g}>�w}��w��r��C ...
@budarin
Copy link
Author

budarin commented Apr 20, 2018

I've found that there is another package in my node_modules folder with name 'image-size' so I changed loaders name to

{
                test: /\.(svg|png|jpg|gif)$/,
                include: path.resolve('./src'),
                exclude: path.resolve('node_modules'),
                use: {
                    loader: 'image-size-loader',
                    options: {
                        name: 'img/[name].[hash:7].[ext]',
                    },
                },
            }

and got another error:

ERROR in ./src/common/assets/404.png
Module build failed: TypeError: Cannot read property 'context' of undefined

@budarin
Copy link
Author

budarin commented Apr 20, 2018

Finally - adding context option makes loader to work properly

            {
                test: /\.(svg|png|jpg|gif)$/,
                include: path.resolve('./src'),
                exclude: path.resolve('node_modules'),
                use: {
                    loader: 'image-size-loader',
                    options: {
                        name: 'img/[name].[hash:7].[ext]',
                        context: path.resolve(__dirname, 'src'),
                    },
                },
            }

something should be documented or fixed

@adamaslan
Copy link

making changes to an old repo and getting a similar error:

./src/Assets/media/HeaderImage.jpg Module build failed: TypeError [ERR_INVALID_ARG_TYPE]: The "from" argument must be of type string. Received undefined

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