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

Issue with webpack cache-loader。 #126

Closed
gui-killer opened this issue Jun 30, 2020 · 2 comments · Fixed by #151
Closed

Issue with webpack cache-loader。 #126

gui-killer opened this issue Jun 30, 2020 · 2 comments · Fixed by #151

Comments

@gui-killer
Copy link

gui-killer commented Jun 30, 2020

When i build my svelte app by webpack with cache-loader introduced, i've got an error:

typeError: stats.mtime.getTime is not a function
    at FS.stat (/Users/xxx/svelte-webpack/node_modules/cache-loader/dist/index.js:114:33)
    at process.nextTick (/Users/xxx/svelte-webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:85:15)
    at process._tickCallback (internal/process/next_tick.js:61:11)
    ...

And then i print out the stats object into the terminal to find out what the 'mtime' key is, the logs are as below:

log => Stats {
  dev: 16777220,
  mode: 33188,
  nlink: 1,
  uid: 501,
  gid: 20,
  rdev: 0,
  blksize: 4194304,
  ino: 15306205,
  size: 51,
  blocks: 8,
  atimeMs: 1593482967553.3503,
  mtimeMs: 499162500000,
  ctimeMs: 1592617381679.1177,
  birthtimeMs: 499162500000,
  atime: 2020-06-30T02:09:27.553Z,
  mtime: 1985-10-26T08:15:00.000Z,
  ctime: 2020-06-20T01:43:01.679Z,
  birthtime: 1985-10-26T08:15:00.000Z }

log => VirtualStats {
  dev: 8675309,
  nlink: 0,
  uid: 1000,
  gid: 1000,
  rdev: 0,
  blksize: 4096,
  ino: 45000000,
  mode: 33188,
  size: 1219,
  blocks: 0,
  atime: 1593483324657,
  mtime: 1593483324657,
  ctime: 1593483324657,
  birthtime: 1593483324657 }

According to these, we can see the mtime is not a date object in VirtualStats which is provided in svelte-loader/lib/virtual.js:

// Starts in line 49.
VirtualModulesPlugin.prototype.writeModule = function(filePath, contents) {
    var len = contents ? contents.length : 0;
    var time = Date.now(); // Here it is, it's just a time stamp, not a date object.

    var stats = new VirtualStats({
        // ...
        mtime: time,
        // ...
    });
    // ...
};

But webpack cache-loader treats the mtime as a date object, and will invoke its getTime method, that's the problem!

@gui-killer
Copy link
Author

gui-killer commented Jun 30, 2020

Bye the way, the build env is production env, and i introduce the mini-css-extract-plugin to separate the css codes to individual css files from js bundle codes. And range the cache-loader after the mini-css-extract-plugin, to make sure it does not cache the result of mini-css-extract-plugin.

But it is all right in the dev environment, i don't what's the different between them.

@Conduitry
Copy link
Member

It sounds like this is what #125 is intended to solve.

non25 added a commit to non25/svelte-loader that referenced this issue Jan 13, 2021
non25 added a commit to non25/svelte-loader that referenced this issue Jan 13, 2021
non25 added a commit to non25/svelte-loader that referenced this issue Jan 13, 2021
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.

2 participants