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

AliasFieldPlugin.apply + lodash: resolving the wrong toString #118

Closed
Fconstant opened this issue Sep 20, 2017 · 16 comments · Fixed by #340
Closed

AliasFieldPlugin.apply + lodash: resolving the wrong toString #118

Fconstant opened this issue Sep 20, 2017 · 16 comments · Fixed by #340

Comments

@Fconstant
Copy link

When resolving "./toString" from lodash, data2 on AliasFieldPlugin.js is removing the ./ from "./toString" of lodash, causing fieldData to get the default function toString() of every object.

Resulting in:

       var idxQuery = identifier.indexOf("?");
                                  ^

TypeError: identifier.indexOf is not a function
    at Resolver.parse (/Users/fcconstantino/Projects/@products/@crefisa/NetBankApp/node_modules/enhanced-resolve/lib/Resolver.js:181:28)
    at Resolver.<anonymous> (/Users/fcconstantino/Projects/@products/@crefisa/NetBankApp/node_modules/enhanced-resolve/lib/ParsePlugin.js:17:25)
    at Resolver.applyPluginsAsyncSeriesBailResult1 (/Users/fcconstantino/Projects/@products/@crefisa/NetBankApp/node_modules/tapable/lib/Tapable.js:256:13)
    at runNormal (/Users/fcconstantino/Projects/@products/@crefisa/NetBankApp/node_modules/enhanced-resolve/lib/Resolver.js:130:20)
    at Resolver.doResolve (/Users/fcconstantino/Projects/@products/@crefisa/NetBankApp/node_modules/enhanced-resolve/lib/Resolver.js:116:3)
    at Resolver.<anonymous> (/Users/fcconstantino/Projects/@products/@crefisa/NetBankApp/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:37:12)
    at Resolver.applyPluginsAsyncSeriesBailResult1 (/Users/fcconstantino/Projects/@products/@crefisa/NetBankApp/node_modules/tapable/lib/Tapable.js:256:13)
    at runNormal (/Users/fcconstantino/Projects/@products/@crefisa/NetBankApp/node_modules/enhanced-resolve/lib/Resolver.js:130:20)
    at Resolver.doResolve (/Users/fcconstantino/Projects/@products/@crefisa/NetBankApp/node_modules/enhanced-resolve/lib/Resolver.js:116:3)
    at Resolver.<anonymous> (/Users/fcconstantino/Projects/@products/@crefisa/NetBankApp/node_modules/enhanced-resolve/lib/AliasFieldPlugin.js:49:12)

Something I couldn't find is: Who is calling the AliasFieldPlugin?

A simple and easy fix was to do something like this:

if (typeof data === 'function') {
    return callback();
}

OBS: I'm also using Haul, which uses an older version of webpack, but still the latest version of enhanced-resolve

Using Version
npm 5.4.2
webpack 2.7.0
enhanced-resolve 3.4.1
lodash 4.17.4
haul 1.0.0-beta.5
@omatrot
Copy link

omatrot commented Dec 17, 2017

I have the same error using sjcl in a ReactJS app (webpack). Works fine in React Native (Babel) though.

@omatrot
Copy link

omatrot commented Dec 17, 2017

Solved it by replacing sjcl with jwt-decode because I only need to deal with JWT Tokens

@sokra
Copy link
Member

sokra commented Jan 4, 2018

Send a PR.

Object.prototype.hasOwnProperty.call(someObject, someProperty)

@Fconstant
Copy link
Author

@sokra Sorry, I didn't understand what you meant. What am I supposed to do with hasOwnProperty?

@domoritz
Copy link

Could this be causing jupyterlab/jupyter-renderers#91?

@Fconstant
Copy link
Author

Fconstant commented Jan 30, 2018

@domoritz Almost. In your case identifier is null. In this case, identifier is not null but indexOf is not a function. But it is the same location that triggers the error.

@dylanslade
Copy link

Has any progress been made?

@alexander-akait
Copy link
Member

Need reproducible test repo, thanks!

@sentenza
Copy link

The only workaround I found for this issue is adding:

"browser": {
    "crypto": true
  }

to my package.json. @evilebottnawi you can find the repo here

@ghost
Copy link

ghost commented Dec 30, 2018

Is @sentenza workaround working for everyone ? Didnt solve it for me..

@khalidhoffman
Copy link

@ArThoX I think you may just need to pass some path string instead of a boolean

@alexander-akait
Copy link
Member

alexander-akait commented Jul 16, 2020

I think here the problem with package.json, maybe somebody can create reproducible test repo?

@sokra
Copy link
Member

sokra commented Jul 16, 2020

I think we need to check hasOwnProperty to avoid receiving Object prototype methods

@alexander-akait
Copy link
Member

Yep, just want to find broken example

@pmmmwh
Copy link

pmmmwh commented Apr 4, 2022

I think this will break reliably - a couple helpers in lodash mutates function prototype, in particular anything related to _setToString (e.g. sortBy)

{
  "dependencies": {
    "@pmmmwh/react-refresh-webpack-plugin": "0.5.x",
    "expo": "*"
  },
  "scripts": {
    "start": "expo web"
  }
}

The issue creeps in via whatwg-url which internally uses lodash/sortBy.
(Ref: pmmmwh/react-refresh-webpack-plugin#601)

@vankop
Copy link
Member

vankop commented Apr 4, 2022

yeah, this should be fixed..

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.

10 participants