hard-source-webpack-plugin icon indicating copy to clipboard operation
hard-source-webpack-plugin copied to clipboard

Trigger hard-source error after syntax error

Open Huai-Kang opened this issue 6 years ago • 14 comments

  • Step 1, trigger a js syntax error
ERROR in ./static/shared/js/component/add-to-cart.js
Module build failed: SyntaxError: Unexpected token, expected ; (13:15)

  11 |  */
  12 |
> 13 | var injectTapE ventPlugin = require("react-tap-event-plugin");
     |                ^
  14 | injectTapEventPlugin();
  15 | var HeadIcon = Tool.getComponent('HeadIcon');
  16 | /**

 @ ./static/shared/js/plugin/quickShop.js 27:0-57
 @ ./static/stylewe/pc/js/home.js
  • Then, trigger a hard-source error after I fixed js syntax error
[hardsource:5ce021c9] Using 20 MB of disk space.
(node:26025) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 51): TypeError: Cannot read property 'indexOf' of undefined
(node:26025) [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.
  • Restart npm scripts to compile app, then I got anthor error
[hardsource:5ce021c9] Using 20 MB of disk space.
[hardsource:5ce021c9] Tracking node dependencies with: package-lock.json, yarn.lock.
[hardsource:5ce021c9] Reading from cache 5ce021c9...
/Users/feel-joy/Code/stylewe/node_modules/loader-runner/lib/LoaderRunner.js:19
	var i = req.indexOf("?");
	           ^

TypeError: Cannot read property 'indexOf' of undefined
    at splitQuery (/Users/Code/stylewe/node_modules/loader-runner/lib/LoaderRunner.js:19:13)
    at getContext (/Users/Code/stylewe/node_modules/loader-runner/lib/LoaderRunner.js:238:17)
    at new NormalModule (/Users/Code/stylewe/node_modules/webpack/lib/NormalModule.js:66:18)
    at Object.thaw (/Users/fCode/stylewe/node_modules/hard-source-webpack-plugin/lib/util/serial.js:199:12)
    at Object.thaw (/Users/Code/stylewe/node_modules/hard-source-webpack-plugin/lib/util/serial.js:216:25)
    at Compiler.pluginCompat.tap (/Users/Code/stylewe/node_modules/hard-source-webpack-plugin/lib/TransformNormalModulePlugin.js:654:30)
    at Compiler.applyPluginsWaterfall (/Users/Code/stylewe/node_modules/tapable/lib/Tapable.js:92:24)
    at Object.exports.call (/Users/Code/stylewe/node_modules/hard-source-webpack-plugin/lib/util/plugin-compat.js:175:38)
    at thaw (/Users/Code/stylewe/node_modules/hard-source-webpack-plugin/lib/SystemArchetype.js:126:29)
    at fetch (/Users/Code/stylewe/node_modules/hard-source-webpack-plugin/lib/SystemArchetype.js:173:16)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `./toolbox/build.js "sw" "pc"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
  • Env
    • Node: 8.0.0
    • Npm: 5.0.0
    • Webpack: 3.0.0
    • Hard-source: 0.12.0

This two bug can be resovled by remove hard-source cache, but I have to rebuild app and cache, this will take a lot of time, can someone help me to resolve this problem ?

Huai-Kang avatar Aug 19 '18 10:08 Huai-Kang

Going out on a limb here, but is it possible that

var injectTapE ventPlugin = require("react-tap-event-plugin"); should be var injectTapEventPlugin = require("react-tap-event-plugin"); ?

Note the missing space. Is the task runner responsible for it, or did you actually miss that typo?

This issue feels unrelated to this plugin.

filipecatraia avatar Aug 22 '18 00:08 filipecatraia

I experience the same issue. I think @Feel-Joy is saying that when he makes a JS syntax error, it causes the cache to become corrupted. I've been getting the error occasionally, but I didn't make the connection with syntax errors until now.

dhulme avatar Aug 28 '18 15:08 dhulme

I'm able to reproduce this error without making any syntax errors. If I trigger a couple of webpack builds back to back (without making any changes to my code), the builds eventually start failing with this error. Any idea on what this could be?

sanchitgera avatar Sep 11 '18 21:09 sanchitgera

We went into this problem too. Now we are using workaround 😉 with clearing cache before build. Our package.json looks like that now

{
  "scripts": {
    "dev": "npm run clear && node .",
    "clear": "rimraf node_modules/.cache"
  }
}

Ohar avatar Sep 13 '18 17:09 Ohar

i am experiencing the same thing. otherwise a great addition to speed up our workflow.

@Ohar your solution of clearing defeats the purpose of the cache

rkingon avatar Sep 17 '18 21:09 rkingon

i am experiencing the same thing. have any solutions?

FengXianGuo avatar Jan 04 '19 04:01 FengXianGuo

We have the same on our CI's (after a couple of builds) with hard-source-webpack-plugin 0.13.1.

/tmp/node_modules/loader-runner/lib/LoaderRunner.js:19
	var i = req.indexOf("?");
	            ^

TypeError: Cannot read property 'indexOf' of undefined
    at splitQuery (/tmp/node_modules/loader-runner/lib/LoaderRunner.js:19:14)
    at getContext (/tmp/node_modules/loader-runner/lib/LoaderRunner.js:238:17)
    at new NormalModule (/tmp/node_modules/webpack/lib/NormalModule.js:69:18)
    at Object.thaw (/tmp/node_modules/hard-source-webpack-plugin/lib/util/serial.js:199:12)
    at Object.thaw (/tmp/node_modules/hard-source-webpack-plugin/lib/util/serial.js:216:25)
    at Compiler.pluginCompat.tap (/tmp/node_modules/hard-source-webpack-plugin/lib/TransformNormalModulePlugin.js:654:30)
    at Compiler.applyPluginsWaterfall (/tmp/node_modules/tapable/lib/Tapable.js:92:24)
    at Object.exports.call (/tmp/node_modules/hard-source-webpack-plugin/lib/util/plugin-compat.js:175:38)
    at thaw (/tmp/node_modules/hard-source-webpack-plugin/lib/SystemArchetype.js:126:29)
    at fetch (/tmp/node_modules/hard-source-webpack-plugin/lib/SystemArchetype.js:173:16)
    at NormalModuleFactory.normalModuleFactoryHooks.createModule.tap (/tmp/node_modules/hard-source-webpack-plugin/lib/TransformNormalModuleFactoryPlugin.js:213:28)
    at NormalModuleFactory.applyPluginsBailResult (/tmp/node_modules/tapable/lib/Tapable.js:129:27)
    at applyPluginsAsyncWaterfall (/tmp/node_modules/webpack/lib/NormalModuleFactory.js:75:31)
    at /tmp/node_modules/tapable/lib/Tapable.js:268:11
    at NormalModuleFactory.params.normalModuleFactory.plugin (/tmp/node_modules/webpack/lib/CompatibilityPlugin.js:52:5)
    at NormalModuleFactory.applyPluginsAsyncWaterfall (/tmp/node_modules/tapable/lib/Tapable.js:272:13)
    at resolver (/tmp/node_modules/webpack/lib/NormalModuleFactory.js:69:10)
    at fromCache (/tmp/node_modules/hard-source-webpack-plugin/lib/TransformNormalModuleFactoryPlugin.js:178:22)
    at /tmp/node_modules/hard-source-webpack-plugin/lib/TransformNormalModuleFactoryPlugin.js:187:22
    at /tmp/node_modules/webpack/lib/NormalModuleFactory.js:59:4
    at applyPluginsAsyncWaterfall (/tmp/node_modules/webpack/lib/NormalModuleFactory.js:234:4)
    at NormalModuleFactory.applyPluginsAsyncWaterfall (/tmp/node_modules/tapable/lib/Tapable.js:260:70)
    at NormalModuleFactory.create (/tmp/node_modules/webpack/lib/NormalModuleFactory.js:218:8)
    at _this.semaphore.acquire (/tmp/node_modules/webpack/lib/Compilation.js:237:13)
    at Semaphore.acquire (/tmp/node_modules/webpack/lib/util/Semaphore.js:16:4)
    at iteratorFactory (/tmp/node_modules/webpack/lib/Compilation.js:235:20)
    at /tmp/node_modules/async/dist/async.js:3083:16
    at eachOfArrayLike (/tmp/node_modules/async/dist/async.js:1003:9)
    at eachOf (/tmp/node_modules/async/dist/async.js:1051:5)
    at Object.eachLimit (/tmp/node_modules/async/dist/async.js:3145:5)

mvgijssel avatar Jan 04 '19 09:01 mvgijssel

@mvgijssel it happens occasionally to us too, just clear the cache before each CI build

rm -rf node_modules/.cache

it will slow down your build, but better than crashing it.

As for development env, I only clear the cache when this happens, which is like every 1/20 builds if I am taking a hard guess, which is fine to clear to cache 5% of the time till this is fixed

akhoury avatar Jan 04 '19 09:01 akhoury

Thanks @akhoury for the tip! Will try that, though like @rkingon mentioned that kinda defeats the purpose of the cache.

mvgijssel avatar Jan 04 '19 10:01 mvgijssel

defeats the purpose of the cache.

it does, if it's happening 100% of the time, but like i mentioned, when in development, it's happening 5% of the time, so.. not too bad.

and when CI building, I am ok cleaning and building without cache (you might not be in your case)

akhoury avatar Jan 04 '19 15:01 akhoury

you should be using separate configs for your build & your dev... only use this for your dev config and you won't need to clear at all during the build.

your prod does things like concat, minify, etc

your dev does things like caching

rkingon avatar Jan 07 '19 06:01 rkingon

you should be using separate configs for your build & your dev... only use this for your dev config and you won't need to clear at all during the build.

your prod does things like concat, minify, etc

your dev does things like caching

True! And we have separate configs just for this.

it does, if it's happening 100% of the time, but like i mentioned, when in development, it's happening 5% of the time, so.. not too bad.

and when CI building, I am ok cleaning and building without cache (you might not be in your case)

One of the bigger benefits of this plugin is that we save a lot of CI time. It's the first plugin to actually save significant time in building assets, which is blocking before we can parallelise our test suite.

mvgijssel avatar Jan 07 '19 10:01 mvgijssel

I have the same problem, it's happening 100% of the time, I got same error:

TypeError: Cannot read property 'indexOf' of undefined
    at splitQuery (/Users/user/work/moviepro-h5/node_modules/[email protected]@loader-runner/lib/LoaderRunner.js:19:14)
    at getContext (/Users/user/work/moviepro-h5/node_modules/[email protected]@loader-runner/lib/LoaderRunner.js:238:17)
    at new NormalModule (/Users/user/work/moviepro-h5/node_modules/[email protected]@webpack/lib/NormalModule.js:67:18)
    at Object.thaw (/Users/user/work/moviepro-h5/node_modules/[email protected]@hard-source-webpack-plugin/lib/util/serial.js:200:12)
    at Object.thaw (/Users/user/work/moviepro-h5/node_modules/[email protected]@hard-source-webpack-plugin/lib/util/serial.js:217:25)
    at Compiler.pluginCompat.tap (/Users/user/work/moviepro-h5/node_modules/[email protected]@hard-source-webpack-plugin/lib/TransformNormalModulePlugin.js:654:30)
    at Compiler.applyPluginsWaterfall (/Users/user/work/moviepro-h5/node_modules/[email protected]@tapable/lib/Tapable.js:92:24)
    at Object.exports.call (/Users/user/work/moviepro-h5/node_modules/[email protected]@hard-source-webpack-plugin/lib/util/plugin-compat.js:175:38)
    at thaw (/Users/user/work/moviepro-h5/node_modules/[email protected]@hard-source-webpack-plugin/lib/SystemArchetype.js:126:29)
    at fetch (/Users/user/work/moviepro-h5/node_modules/[email protected]@hard-source-webpack-plugin/lib/SystemArchetype.js:173:16)

FengXianGuo avatar Jan 08 '19 01:01 FengXianGuo