webpack: TypeError: Data must be a string or a buffer
Using the latest 2.2.0
release, although the error was on rc.4
before I updated too.
crypto.js:73
this._handle.update(data, encoding);
^
TypeError: Data must be a string or a buffer
at TypeError (native)
at Hash.update (crypto.js:73:16)
at HarmonyExportImportedSpecifierDependency.updateHash (/Users/kuchumovn/work/webapp/frontend/node_modules/webpack/lib/dependencies/HarmonyExportImportedSpecifierDependency.js:144:8)
at /Users/kuchumovn/work/webapp/frontend/node_modules/webpack/lib/DependenciesBlock.js:33:5
at Array.forEach (native)
at NormalModule.DependenciesBlock.updateHash (/Users/kuchumovn/work/webapp/frontend/node_modules/webpack/lib/DependenciesBlock.js:32:20)
at NormalModule.Module.updateHash (/Users/kuchumovn/work/webapp/frontend/node_modules/webpack/lib/Module.js:162:41)
at NormalModule.updateHash (/Users/kuchumovn/work/webapp/frontend/node_modules/webpack/lib/NormalModule.js:327:30)
at modules.forEach.m (/Users/kuchumovn/work/webapp/frontend/node_modules/webpack/lib/Chunk.js:253:31)
at Array.forEach (native)
I supposse it’s computing a hash for a file, and a file is empty (?) or non-existent or something like that. Anyway no clue on the real error in this error message.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 76
- Comments: 92 (4 by maintainers)
Commits related to this issue
- Merge pull request #4368 from about-code/master TypeError: Data must be a string or a buffer (#4072) — committed to webpack/webpack by sokra 7 years ago
Here is a workaround to help you to find the wrong import.
Let’s say you have some wrong import somewhere in your code:
You can improve the error message by manually editing the following file: node_modules/webpack/lib/dependencies/HarmonyExportImportedSpecifierDependency.js and insert some log at line 144:
So you get this more explicit message:
Finally, search for ‘./missing-file’ string in your project to find which file contains the wrong import.
The problems occurs when trying to export a file not present on the disk. While import error show a clear error message:
The error during export does not help :
I get that problem when I try to reexport not existing class from file, for example
export { ManageUsersComponent } from './manage-users.component';
when ManageUsersComponent does not exist.I get it, its a problem with code, but I would appreciate better error message instead of:
We have also the same error!!! With Version 2 from Webpack we have only problems!
Just hit the same problem here. Upgrading to Node 7.4.0 did not resolve the issue for me.
Yup. It’s missing a check. Or even if it skips an explicit check, it should fail in a way that allows the user to fix the problem.
For those using
@angular/material
, we got this error using the latest release of the master branch.https://github.com/angular/material2/issues/5320
Having
"@angular/material": "2.0.0-beta.7"
in our package.json file fixed the compilation error.I had the same problem. Upgrading node from 6.9.4 to 7.4.0 solved the problem for me.
In my case it was this line:
I deleted the
./navigator
file but apparently webpack doesn’t check if the file exists, then reads it, getsnull
orundefined
, then feeds this non-existent value to the crypto hash generator and then explodes.Looks like this is a
null
issue. That’s why it errors like that. I wonder if it should fail earlier, though.I did the following change:
This made the error disappear (gives another error, but that’s perhaps expected). That earlier
export
referred to code that doesn’t exist so that might explain thosenull
s. I’m guessing webpack needs to be stricter in this case.I got the same error after making a bunch of changes to the code and now it’s very hard to pinpoint exactly what change is causing the issue. Is there any way to know what file/module is making trouble?
@angular/cdk
was missing on my case.I’ve meet the same issue when replacing react-router with react-router-dom. And finally figured out what happened.
Steps to reproduce this issue:
This is because
react-router-dom
also usereact-router
as dependency in code belowwhen you uninstall react-router, npm just naively remove it without check if it’s other module’s dependency.
+1
Another case to watch out for is if you override
resolve.extensions
to not include.js
(because I don’t have any javascript!) and are importing an es2015 module supporting package fromnode_modules
, likereact-redux
.@Toub Someone give this guy a medal. Thank you Lord! Freaking
@angular/cdk.
Suggestion from @Toub saved me several hours.
Should be part added to web pack.
Yes. Install @angular/cdk
On 11-Jul-2017 6:48 PM, “Kai” notifications@github.com wrote:
@Toub
I tried your debugging code but get nothing back below is the error and my edit to the file you specified
`** NG Live Development Server is running on http://localhost:4200. ** 86% hashingcrypto.js:74 this._handle.update(data, encoding); ^
TypeError: Data must be a string or a buffer at TypeError (native) at Hash.update (crypto.js:74:16) at HarmonyExportImportedSpecifierDependency.updateHash (C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\dependencies\HarmonyExportImportedSpecifierD ependency.js:144:8) at C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\DependenciesBlock.js:33:5 at Array.forEach (native) at NormalModule.DependenciesBlock.updateHash (C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\DependenciesBlock.js:32:20) at NormalModule.Module.updateHash (C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\Module.js:162:41) at NormalModule.updateHash (C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\NormalModule.js:327:30) at modules.forEach.m (C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\Chunk.js:253:31) at Array.forEach (native) at Chunk.updateHash (C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\Chunk.js:253:16) at Compilation.createHash (C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\Compilation.js:989:10) at sealPart2 (C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\Compilation.js:580:9) at next (C:\wamp\www\nationalgrid\public_cli\node_modules\tapable\lib\Tapable.js:202:11) at Compilation.<anonymous> (C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\ProgressPlugin.js:110:5) at next (C:\wamp\www\nationalgrid\public_cli\node_modules\tapable\lib\Tapable.js:204:14) at ExtractTextPlugin.<anonymous> (C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\index.js:317:5) at C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:421:16 at iteratorCallback (C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:998:13) at C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:906:16 at C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\index.js:301:6 at C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:421:16 at iteratorCallback (C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:998:13) at C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:906:16 at C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\index.js:298:13 at C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:3083:16 at eachOfArrayLike (C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:1003:9) at eachOf (C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:1051:5) at Object.eachLimit (C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:3145:5) at C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\index.js:271:11 at C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:3083:16 at eachOfArrayLike (C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:1003:9) at eachOf (C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:1051:5) at Object.eachLimit (C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\node_modules\async\dist\async.js:3145:5) at ExtractTextPlugin.<anonymous> (C:\wamp\www\nationalgrid\public_cli\node_modules\extract-text-webpack-plugin\index.js:268:10) at Compilation.applyPluginsAsyncSeries (C:\wamp\www\nationalgrid\public_cli\node_modules\tapable\lib\Tapable.js:206:13) at Compilation.seal (C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\Compilation.js:545:8) at C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\Compiler.js:474:16 at C:\wamp\www\nationalgrid\public_cli\node_modules\tapable\lib\Tapable.js:289:11 at _addModuleChain (C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\Compilation.js:452:11) at processModuleDependencies.err (C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\Compilation.js:423:13) at _combinedTickCallback (internal/process/next_tick.js:73:7) at process._tickCallback (internal/process/next_tick.js:104:9)`
updateHash(hash) { super.updateHash(hash); const hashValue = this.getHashValue(this.importDependency.module); if (this.importDependency.module != null){ // console.log('Module resource: ', this.importDependency.module.resource); }else{ console.log('\nFile not found: ', this.importDependency); } hash.update(hashValue); }
I had the same issue because of
instead of
I think the error wasn’t very clear but your comments help me.
@stephenad are you sure to edit the right file?
Your stack trace is still at line 144, so you probably edited an other version of this file.
Try again with C:\wamp\www\nationalgrid\public_cli\node_modules\angular-cli\node_modules\webpack\lib\dependencies\HarmonyExportImportedSpecifierDependency.js
Please ignore my above comment.
for anyone using angular material2 in their project, here’s the fix:
npm install – --save @angular/cdk
this is because material 2 now uses cdk as a dependency. CDK is the short form of component dev kit. This signifies that these are general-purpose tools for building components that are not coupled to Material Design
Ref: https://github.com/angular/material2/blob/master/guides/getting-started.md#step-1-install-angular-material-and-angular-cdk
Like @michaelz and @dargoan I had an issue with
@angular/material
package. Be sure to have"@angular/material": "2.0.0-beta.7"
and not"@angular/material": "^2.0.0-beta.7"
. After cleaningnode_modules
, thennpm install
all is working fine.Retested this morning, with
"@angular/material": "2.0.0-beta.7"
as suggested by @michaelz . It worked nice. Also, yesterday, there was a problem with npm registry when trying to fecth latest angular packages. Now resolved.@herlon214 , this bug is fixed indeed, I was getting this error because yarn installed maximum satisfying version of webpack (2.2.1) and I resolved this by adding webpack to dependencies explicitly, now it updates to maximum available
For me is fail to configure
resolve.extensions
cause this error. Add the missing.vue
extensions solve the problem. FYI:Thx @Toub you help figure this out!
Sorry I am not a webpack expert, please open a ticket on Stackoverflow.
yes webpack 4 so how i solve this ? 😦 @Toub
Thanks @Toub This was killing me! And thanks @carlosvillademor for pointing me to this post!
@Toub You saved my day. Really thanks