plasticine / inject-loader

💉📦 A Webpack loader for injecting code into modules via their dependencies.
https://www.npmjs.com/package/inject-loader
MIT License
482 stars 47 forks source link

Not working for me #41

Closed sgriffin916 closed 7 years ago

sgriffin916 commented 7 years ago

I have tried in three different solutions and can't seem to get inject-loader to work. I even downloaded the example you provided, did a npm install and then npm run test and get the same error.

image

I am sure it is something that I am misunderstanding and would appreciate any guidance.

huumanoid commented 7 years ago

Hello @sgriffin916. I've cloned this repo under my windows:

git clone https://github.com/plasticine/inject-loader.git
cd inject-loader/example/webpack2-babel
npm install
npm run test

As a result, I've experienced the same issue!

But after I've mentioned that there is indeed no inject-loader in both node_modules and ../.. (see webpack.conf.js -> resolveLoader.modules)

To launch tests successfully, I've run the following command in inject-loader/example/webpack2-babel: npm install inject-request OR

cd ../..
npm install # i.e. I've performed npm install for the root of the repo

Have you performed npm install for both the example and the main project?

So... That's it. For some reason, webpack is unable to find inject-loader in your project. Probably, it would be helpful if you provide us your webpack config.

sgriffin916 commented 7 years ago

So doing npm install inject-loader got the example project for me working. Inspired, I did the following on my project, running the tests after all three and all three still failed. Bummer.

I did discover that if I change it from - const inject = require("inject-loader!EnsureLoggedIn"); to - const inject = require("inject-loader!./../../src/containers/EnsureLoggedIn"); that I don't get the module not find error message but inject is not a function error.

Attached is my webpack config file. webpack.txt

Thanks!

sgriffin916 commented 7 years ago

I ended up getting it to work using sinon.stub(). Thanks for getting back with me.