public icon indicating copy to clipboard operation
public copied to clipboard

can't find require() resources

Open tsawan opened this issue 10 years ago • 12 comments

Issue description or question

While testing a Angular 2 component, wallaby is giving error that it can't find css file and html file that is required. e.g., require('./home.css') or require('./home.html'). If I change the code to use styleUrl and templateUrl without require, it works fine. since I am using webpack so I use require for all css and html files.

Code editor or IDE name and version

IntelliJ IDEA v15

OS name and version

Windows

tsawan avatar May 04 '16 10:05 tsawan

Could you please share your wallaby config?

ArtemGovorov avatar May 04 '16 10:05 ArtemGovorov

module.exports = function (wallaby) { return { "files": [ "src/*/.ts", { pattern: 'node_modules/es6-shim/es6-shim.js', instrument: false} ],

    "tests": [
        "test/**/*Spec.ts"
    ],
    "compilers": {
        "**/*.ts": wallaby.compilers.typeScript({})
    },
postprocessor: webpackPostprocessor,

bootstrap: function() {
   window.__moduleBundler.loadTests();
}

}

};

tsawan avatar May 04 '16 10:05 tsawan

You need to include patterns for your css and html files to your files list. I don't see how your webpackPostprocessor is defined since you skipped that part, but you may also need to add css and html webpack loaders in its config.

ArtemGovorov avatar May 04 '16 10:05 ArtemGovorov

I didn't skip any config part

Then where is in the config you have pasted the webpackPostprocessor is defined? If you start the config you pasted you'll get an error because of the undefined variable.

is there a way to configure webpackPostProcessor to include css files?

You don't need to do it. You need to include css and html files to your files list, just like described in the docs I have referenced.

ArtemGovorov avatar May 04 '16 10:05 ArtemGovorov

Depending on how your webpackPostProcessor is defined, you may to also add css and html webpack loaders, the same way you do in your webpack config. For example, this config adds some webpack specific config options, like externals and resolve. The same way you may add your loaders. You may find more example and generally webpack integration notes in this docs section.

ArtemGovorov avatar May 04 '16 10:05 ArtemGovorov

sorry, I missed to include webpackPostprocessor in config above. that was just a function call with no config options.

I've copied the loaders from main webpack.config.js and pasted in webpackPostprocessor block. It's still giving "Cannot find module "./home.css".

I've also tried to add the file pattern as pattern: 'src/*/.css' but getting same error. I think adding files pattern won't work since I am using require to bundle the css files. Not sure why the loaders are not working since my webpack bundle is working fine otherwise.

Any more idea(s)?

tsawan avatar May 04 '16 11:05 tsawan

Both loaders that you have pasted in the webpackPostprocessor block, and patterns for css (and html) in the files list are required. CSS files are required in the list, so that wallaby.js knows it needs to copy them to its cache (that it runs webpack build on).

The Cannot find module means that webpack can't find the home.css file for some reason. Please double check the pattern in the files list, and if it is correct, try checking if your css files end up in wallaby cache. You may find the cache location for your project like described here.

If your css files are in the instrumented folder in the cache, then I'm out of ideas. In this case, please create a sample GitHub repo demonstrating your issue and I'll have a look.

ArtemGovorov avatar May 04 '16 11:05 ArtemGovorov

Forgot to mention - to get that debugging info with the project cache to wallaby console you'll also need to set the debug: true flag in your wallaby config.

ArtemGovorov avatar May 04 '16 11:05 ArtemGovorov

css files are in the cache but the debug log shows the following No compilers found for src/app/home/home.css file src/app/home/home.css is not instrumented by core

in webpackPostprocessor I have the following. loaders: [ { test: /.css$/, loaders: ['style', 'css'] }, { test: /.html$/, loader: 'raw' } ]

my css is referred in component like styles: [ require('./home.css').toString() ]

toString() was added because of a bug (solution found from SO).

tsawan avatar May 04 '16 11:05 tsawan

css files are in the cache but the debug log shows the following No compilers found for src/app/home/home.css file src/app/home/home.css is not instrumented by core

This is ok. toString() should also not be an issue. I'm out of ideas. Please create a simple repository with your config and that home file and I'll have a look into what is going on.

ArtemGovorov avatar May 04 '16 11:05 ArtemGovorov

got it working. the loaders in webpackPostprocessor had to be in module block. Thanks for help.

tsawan avatar May 04 '16 11:05 tsawan

Ok, thanks for the update. Yes, when constructing the wallabyPostprocessor, webpack options has to be in the exact same format like in your webpack config.

ArtemGovorov avatar May 04 '16 11:05 ArtemGovorov