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

SourceMap option does not work on GitLab CI #51

Closed
ofhouse opened this issue Jan 5, 2021 · 33 comments · Fixed by #53
Closed

SourceMap option does not work on GitLab CI #51

ofhouse opened this issue Jan 5, 2021 · 33 comments · Fixed by #53

Comments

@ofhouse
Copy link

ofhouse commented Jan 5, 2021

  • Operating System: GitLab CI - Docker/Ubuntu
  • Node Version: 14.15.3
  • NPM Version: 6.14.9
  • webpack Version: 5.11.1
  • css-minimizer-webpack-plugin Version: 1.1.5

Expected Behavior

Should produce a sourcemap on GitLab CI in the same way as on my local machine.

Actual Behavior

Fails with the following error message:

(node:47) UnhandledPromiseRejectionWarning: Error: "version" is a required argument.
    at Object.getArg (/builds/ofhouse/stackoverflow-65355772/node_modules/source-map/lib/util.js:24:11)
    at new BasicSourceMapConsumer (/builds/ofhouse/stackoverflow-65355772/node_modules/source-map/lib/source-map-consumer.js:294:22)
    at new SourceMapConsumer (/builds/ofhouse/stackoverflow-65355772/node_modules/source-map/lib/source-map-consumer.js:22:7)
    at SourceMapSource.node (/builds/ofhouse/stackoverflow-65355772/node_modules/webpack-sources/lib/SourceMapSource.js:193:4)
    at exports.getSourceAndMap (/builds/ofhouse/stackoverflow-65355772/node_modules/webpack-sources/lib/helpers.js:20:27)
    at SourceMapSource.sourceAndMap (/builds/ofhouse/stackoverflow-65355772/node_modules/webpack-sources/lib/SourceMapSource.js:184:10)
    at getTaskForFile (/builds/ofhouse/stackoverflow-65355772/node_modules/webpack/lib/SourceMapDevToolPlugin.js:78:30)
    at /builds/ofhouse/stackoverflow-65355772/node_modules/webpack/lib/SourceMapDevToolPlugin.js:266:22
    at /builds/ofhouse/stackoverflow-65355772/node_modules/webpack/lib/Cache.js:93:5
    at Hook.eval [as callAsync] (eval at create (/builds/ofhouse/stackoverflow-65355772/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)

Code

Reproduction repository: https://gitlab.com/ofhouse/stackoverflow-65355772

How Do We Reproduce?

  1. Checkout the repository locally and run npm run build (success)
  2. Upload it to GitLab.com and let GitLab CI run (fails)
    Example output from the current HEAD of the repository: https://gitlab.com/ofhouse/stackoverflow-65355772/-/jobs/945541367

I've tried out many different setups but I always fail to reproduce the issue locally.
Even running inside the same docker image with

docker run --rm -v $(pwd):/tmp node:14-alpine sh -c "cd /tmp && npm ci && npm run build"

does not let me reproduce the issue.

I have no idea how I could abstract this issue further, so my hope is that somebody here has an idea what's happening 🙏.

Edit:
What it makes it even stranger is that it also runs successfully on GitHub actions: https://github.com/ofhouse/stackoverflow-65355772/runs/1652026529

@alexander-akait
Copy link
Member

You have broken source maps, please open an issue in GitLab CI, it was from source-map package, and it is right message

@alexander-akait
Copy link
Member

alexander-akait commented Jan 6, 2021

Anyway the main problem here:

node:47) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:47) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Try to set this flag (--unhandled-rejections=strict) and say what is the error

@ofhouse
Copy link
Author

ofhouse commented Jan 6, 2021

Thanks for the quick response,
setting --unhandled-rejections=strict does not really give more information:

/builds/ofhouse/stackoverflow-65355772/node_modules/source-map/lib/util.js:24
    throw new Error('"' + aName + '" is a required argument.');
          ^
Error: "version" is a required argument.
    at Object.getArg (/builds/ofhouse/stackoverflow-65355772/node_modules/source-map/lib/util.js:24:11)
    at new BasicSourceMapConsumer (/builds/ofhouse/stackoverflow-65355772/node_modules/source-map/lib/source-map-consumer.js:294:22)
    at new SourceMapConsumer (/builds/ofhouse/stackoverflow-65355772/node_modules/source-map/lib/source-map-consumer.js:22:7)
    at SourceMapSource.node (/builds/ofhouse/stackoverflow-65355772/node_modules/webpack-sources/lib/SourceMapSource.js:193:4)
    at exports.getSourceAndMap (/builds/ofhouse/stackoverflow-65355772/node_modules/webpack-sources/lib/helpers.js:20:27)
    at SourceMapSource.sourceAndMap (/builds/ofhouse/stackoverflow-65355772/node_modules/webpack-sources/lib/SourceMapSource.js:184:10)
    at getTaskForFile (/builds/ofhouse/stackoverflow-65355772/node_modules/webpack/lib/SourceMapDevToolPlugin.js:78:30)
    at /builds/ofhouse/stackoverflow-65355772/node_modules/webpack/lib/SourceMapDevToolPlugin.js:266:22
    at /builds/ofhouse/stackoverflow-65355772/node_modules/webpack/lib/Cache.js:93:5
    at Hook.eval [as callAsync] (eval at create (/builds/ofhouse/stackoverflow-65355772/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)

(Original log: https://gitlab.com/ofhouse/stackoverflow-65355772/-/jobs/947104530)

I agree that the Error message comes from a broken sourcemap but I don't understand who has generated the sourcemap. The source-map package here only tries to parse the broken sourcemap and throws the error but the package was not responsible for creating the broken sourcemap, or am I wrong?

@alexander-akait
Copy link
Member

alexander-akait commented Jan 6, 2021

If you remove the sourceMap option, do all work fine? By default we respect the devtool option, so it should work without this option

@ofhouse
Copy link
Author

ofhouse commented Jan 6, 2021

No, still got the same message: https://gitlab.com/ofhouse/stackoverflow-65355772/-/jobs/947141852

@alexander-akait
Copy link
Member

Can you monkey patching your code of plugin for CI here https://github.com/webpack-contrib/css-minimizer-webpack-plugin/blob/master/src/index.js#L266 (just put console.log(map)) and here https://github.com/webpack-contrib/css-minimizer-webpack-plugin/blob/master/src/index.js#L349 (console.log(map))?

@alexander-akait
Copy link
Member

What is you use for tests? Jest? What is environment? jsdom or node?

@ofhouse
Copy link
Author

ofhouse commented Jan 6, 2021

The output from L266:

{
  version: 3,
  sources: [ 'webpack://./src/style.css' ],
  names: [],
  mappings: 'AAAA,oBAAoB;AACpB;EACE,4BAA4B;AAC9B',
  file: 'x',
  sourcesContent: [
    '/* Sample CSS file */\nbody {\n  background-color: blueviolet;\n}\n'
  ]
}

Output from L349:

SourceMapGenerator {
  _file: 'main.css',
  _sourceRoot: null,
  _skipValidation: false,
  _sources: ArraySet {
    _array: [ 'webpack://./src/style.css' ],
    _set: Map(1) { 'webpack://./src/style.css' => 0 }
  },
  _names: ArraySet { _array: [], _set: Map(0) {} },
  _mappings: MappingList {
    _array: [ [Object], [Object], [Object] ],
    _sorted: true,
    _last: {
      generatedLine: 1,
      generatedColumn: 29,
      originalLine: 4,
      originalColumn: 0,
      source: 'webpack://./src/style.css',
      name: null
    }
  },
  _sourcesContents: [Object: null prototype] {
    'main.css': '/* Sample CSS file */\nbody {\n  background-color: blueviolet;\n}\n\n',
    'webpack://./src/style.css': '/* Sample CSS file */\nbody {\n  background-color: blueviolet;\n}\n'
  }
}

Original log: https://gitlab.com/ofhouse/stackoverflow-65355772/-/jobs/947196486

I am familiar with jest but for this project I just use webpack cli to trigger the build: https://gitlab.com/ofhouse/stackoverflow-65355772/-/blob/main/package.json#L8

@alexander-akait
Copy link
Member

alexander-akait commented Jan 6, 2021

hm, very weird, can you try to run console.log(map.toString()) for https://github.com/webpack-contrib/css-minimizer-webpack-plugin/blob/master/src/index.js#L349, just ensure, without plugin all is fine?

@ofhouse
Copy link
Author

ofhouse commented Jan 6, 2021

Oh yes, of course.
L349:

{
  "version": 3,
  "sources": [
    "webpack://./src/style.css"
  ],
  "names": [],
  "mappings": "AACA,KACE,wBACF",
  "file": "main.css",
  "sourcesContent": [
    "/* Sample CSS file */\nbody {\n  background-color: blueviolet;\n}\n"
  ]
}

Logged it also from node_modules/source-map/lib/source-map-consumer.js:294 (where the sourcemap is parsed), and it also has the same output there:

{
  "version": 3,
  "sources": [
    "webpack://./src/style.css"
  ],
  "names": [],
  "mappings": "AACA,KACE,wBACF",
  "file": "main.css",
  "sourcesContent": [
    "/* Sample CSS file */\nbody {\n  background-color: blueviolet;\n}\n"
  ]
}

Original log: https://gitlab.com/ofhouse/stackoverflow-65355772/-/jobs/947320884

So it seems like you're right and the failure comes from the source-map package.

@alexander-akait
Copy link
Member

Okay, let's do monkey patching this line /builds/ofhouse/stackoverflow-65355772/node_modules/source-map/lib/util.js:24:11, because I don't have ideas what is wrong, feeling that something wrong with Node.js on Github CI

@ofhouse
Copy link
Author

ofhouse commented Jan 6, 2021

Yeah, tested it manually and it returned undefined for aSourceMap['version'] while serializing aSourceMap with JSON.stringify(aSourceMap) gives me the result from above.

@alexander-akait
Copy link
Member

@ofhouse
Copy link
Author

ofhouse commented Jan 6, 2021

Using this code

console.log('aSourceMap (toString)', aSourceMap)
console.log('aSourceMap: ', JSON.stringify(aSourceMap, null, 2));
console.log('RAW Version', aSourceMap['version'])
console.log('Object.getOwnPropertyDescriptor', Object.getOwnPropertyDescriptor(aSourceMap, 'version'))

Gives me the following output:

aSourceMap (toString) SourceMapGenerator {
  _file: 'main.css',
  _sourceRoot: null,
  _skipValidation: false,
  _sources: ArraySet {
    _array: [ 'webpack://./src/style.css' ],
    _set: Map(1) { 'webpack://./src/style.css' => 0 }
  },
  _names: ArraySet { _array: [], _set: Map(0) {} },
  _mappings: MappingList {
    _array: [ [Object], [Object], [Object] ],
    _sorted: true,
    _last: {
      generatedLine: 1,
      generatedColumn: 29,
      originalLine: 4,
      originalColumn: 0,
      source: 'webpack://./src/style.css',
      name: null
    }
  },
  _sourcesContents: [Object: null prototype] {
    'main.css': '/* Sample CSS file */\nbody {\n  background-color: blueviolet;\n}\n\n',
    'webpack://./src/style.css': '/* Sample CSS file */\nbody {\n  background-color: blueviolet;\n}\n'
  }
}
aSourceMap:  {
  "version": 3,
  "sources": [
    "webpack://./src/style.css"
  ],
  "names": [],
  "mappings": "AACA,KACE,wBACF",
  "file": "main.css",
  "sourcesContent": [
    "/* Sample CSS file */\nbody {\n  background-color: blueviolet;\n}\n"
  ]
}
RAW Version undefined
Object.getOwnPropertyDescriptor undefined

I don't get it 🙈 Since it is running on an official Node.js docker image (node:14-alpine) it should not be a problem of Node configuration at this point.

@alexander-akait
Copy link
Member

Okay, we found a problem ⭐ now we need to search who create it, can you put

console.log('aSourceMap (toString)', aSourceMap)
console.log('aSourceMap: ', JSON.stringify(aSourceMap, null, 2));
console.log('RAW Version', aSourceMap['version'])
console.log('Object.getOwnPropertyDescriptor', Object.getOwnPropertyDescriptor(aSourceMap, 'version'))

Here https://github.com/webpack-contrib/css-minimizer-webpack-plugin/blob/master/src/index.js#L349

@alexander-akait
Copy link
Member

And can you try other image for Gitlab CI? Perhaps still something wrong with Node.js

@ofhouse
Copy link
Author

ofhouse commented Jan 6, 2021

Yep, got me the same output in L349:

aSourceMap (toString) SourceMapGenerator {
  _file: 'main.css',
  _sourceRoot: null,
  _skipValidation: false,
  _sources: ArraySet {
    _array: [ 'webpack://./src/style.css' ],
    _set: Map(1) { 'webpack://./src/style.css' => 0 }
  },
  _names: ArraySet { _array: [], _set: Map(0) {} },
  _mappings: MappingList {
    _array: [ [Object], [Object], [Object] ],
    _sorted: true,
    _last: {
      generatedLine: 1,
      generatedColumn: 29,
      originalLine: 4,
      originalColumn: 0,
      source: 'webpack://./src/style.css',
      name: null
    }
  },
  _sourcesContents: [Object: null prototype] {
    'main.css': '/* Sample CSS file */\nbody {\n  background-color: blueviolet;\n}\n\n',
    'webpack://./src/style.css': '/* Sample CSS file */\nbody {\n  background-color: blueviolet;\n}\n'
  }
}
aSourceMap:  {
  "version": 3,
  "sources": [
    "webpack://./src/style.css"
  ],
  "names": [],
  "mappings": "AACA,KACE,wBACF",
  "file": "main.css",
  "sourcesContent": [
    "/* Sample CSS file */\nbody {\n  background-color: blueviolet;\n}\n"
  ]
}
RAW Version undefined
Object.getOwnPropertyDescriptor undefined

(Log: https://gitlab.com/ofhouse/stackoverflow-65355772/-/jobs/947587834)

Will try another image in a second

@ofhouse
Copy link
Author

ofhouse commented Jan 6, 2021

No, tested it with node:15.5.1-stretch and it fails the same way: https://gitlab.com/ofhouse/stackoverflow-65355772/-/jobs/947597744

@alexander-akait
Copy link
Member

alexander-akait commented Jan 6, 2021

Can you try to disable - parallel: false (I think problem with IPC)?

@ofhouse
Copy link
Author

ofhouse commented Jan 6, 2021

Same result with parallel: false: https://gitlab.com/ofhouse/stackoverflow-65355772/-/jobs/947608661
Also tested it with node:12 image, same result.

@alexander-akait
Copy link
Member

Very very very strange, I don't have ideas 😞

@alexander-akait
Copy link
Member

Try to debug it more, maybe we will found something...

@ofhouse
Copy link
Author

ofhouse commented Jan 6, 2021

Ok, no problem. Many thanks for taking the time to help me! 🙂

@ofhouse
Copy link
Author

ofhouse commented Jan 6, 2021

Ok found something:

Setting parallel: false on my local machine lets me reproduce the issue locally (tested it with 2 different machines).
So the GitLab machine triggers parallel: false by default based on the available CPU cores.
So my guess is that the issue only appears on machines with a single CPU core.

@jessedobbelaere
Copy link

I downgraded to v1.1.3 to workaround the issue. Seems to be reproducible since v1.1.4

@alexander-akait
Copy link
Member

@ofhouse give me time to look at this

@ofhouse
Copy link
Author

ofhouse commented Jan 8, 2021

@alexander-akait No problem, take your time.
It's not a critical issue for me, since we can workaround by downgrading or building it locally.

I also updated the main branch of the reproduction repo to include the parallel: false setting: https://gitlab.com/ofhouse/stackoverflow-65355772
So you should be able to checkout and run npm run build to reproduce the issue locally now.

@alexander-akait
Copy link
Member

I think I will release patch version today/tomorrow

@alexander-akait
Copy link
Member

alexander-akait commented Jan 8, 2021

WIP on this

@alexander-akait
Copy link
Member

Please try https://github.com/webpack-contrib/css-minimizer-webpack-plugin/releases/tag/v1.2.0

@jessedobbelaere
Copy link

Upgraded to v1.2.0, webpack builds perfectly here. Thank you! 🙌

@alexander-akait
Copy link
Member

I will check other minimizers on the same problem (WIP)

@ofhouse
Copy link
Author

ofhouse commented Jan 9, 2021

v1.2.0 fixed the issue for me as well! Great work, thank you 👍

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