Open Dinistro opened 8 years ago
Have the same issue.
Will take a look as soon as I have some time ⌚
Has anyone looked at this issue? I'm trying to use the plug in and I'm getting the same error.
"TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined"
I'm sorry about that, I don't have time for this project... Not even using gulp for years anymore
Too bad, this seem like the perfect tool for something I was working on. I'm happy to try and do a PR and fix it. Any ideas what might be causing the issue?
Looking at the error stack, the line that throws is https://github.com/skyrpex/gulp-extract-css-urls/blob/master/lib/index.js#L95.
Maybe result.code
is undefined, and maybe the reason for that is an unexpected error somewhere above.
I could spend some minutes on this if somebody created a minimal repository to reproduce the error.
So I spent about 3 hours trying to get this to work and I didn't have much luck. It might be that I don't understand if I'm using this gulp plugin correctly, but I'm not sure.
Basically I have a CSS file that I'm building using gulp. Inside the CSS file are a handful of "background-image: url()' property tags that are pointing to base64-encoded image files on a CDN that I want to pull into my locally directory.
I tried a lot of basic things first to fix source including updating the the packages and rebuilding the library, but nothing seem to work for me.
I will say that I think part of the problem I was having was the plugin was assuming that the css file had a sourcemap. Mine didn't at first but then I installed the "gulp-sourcemap" plugin and had it producing both an inline comment style sourcemap and then a seperate file version linked to my css file, but neither seem to help.
Yeah for me a lot of the issue started here "file.sourceMap" on line 91. If there is no sourceMap then that makes sense that the file.result would through an error.
So what exactly is --
convertSourceMap .fromObject(file.sourceMap) .toComment({ multiline: true });
expecting and what is it supposed to return?
expecting and what is it supposed to return?
I don't remember much about it but that method will take a sourceMap object (I guess it's sort of an AST) and convert it into an inline sourceMap comment (something like `/ sourceMap: ..... /
Maybe you could try skipping the inline sourceMap step, but I recall that it broke the final sourceMaps in some way:
// const sourceMapComment = convertSourceMap
// .fromObject(file.sourceMap)
// .toComment({ multiline: true });
const contents = file.contents.toString();
const result = rework(contents, { source: file.relative })
.use(url(handle))
.toString();
Hmm, I thought I tried that, but it was after I had tried a handful of other changes and before I added in the sourcemaps piece.
Quick question, based on my initial question should this gulp plug in be able to do what I'm asking it to. Save Base64 images locally?
Okay still not working.
This is the error I'm getting now.
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
It seems to be coming from the handle callback. When I comment that function out it doesn't fail.
Starting at line 49.
Thoughts?
Quick question, based on my initial question should this gulp plug in be able to do what I'm asking it to. Save Base64 images locally?
Oh, it doesn't support that. It skips URLs that begin with data:
.
That error sounds like the new Buffer(result.code)
instruction is receiving undefined instead of a string with the resulting code.
My guess is that there's an error when rework is handling the sources and we aren't doing any error checking.
Quick question, based on my initial question should this gulp plug in be able to do what I'm asking it to. Save Base64 images locally?
Oh, it doesn't support that. It skips URLs that begin with
data:
.
Yeah I saw that in the code, but my images start with "http://", so I assuming it should still work. Correct?
My guess is that there's an error when rework is handling the sources and we aren't doing any error checking.
Okay, so this gives me a starting point. I'll take a deeper dive. Thanks so much.
Quick question, based on my initial question should this gulp plug in be able to do what I'm asking it to. Save Base64 images locally?
Oh, it doesn't support that. It skips URLs that begin with
data:
.Yeah I saw that in the code, but my images start with "http://", so I assuming it should still work. Correct?
Okay, now I understand. There are two problems: lack of documentation about what this plugin solves, and lack of error reporting.
The plugin is supposed to import local files relative to the CSS. For example:
/* assets/styles.css */
.bg {
background: url(./my-bg.jpg);
}
The plugin will import the assets/my-bg.jpg
file. It doesn't handle HTTP/S URLs, only relative files.
I guess it's doable, but I'd suggest manually downloading the files you want to import and leave them in your repository. You can't ensure a file from a URL to always be available when compiling your CSS...
When I try to run this code:
I get this error message:
As far as I know, the
file.sourceMap
in theindex.js
isundefinied
and causes this error.