jouni-kantola / razor-partial-views-webpack-plugin

Plugin for generating ASP.NET Razor partial views for assets built with webpack.
MIT License
13 stars 3 forks source link

Get error "Cannot read property 'tap' of undefined" #69

Closed gwynjudd closed 2 years ago

gwynjudd commented 2 years ago

Hello,

I'm pretty new to using webpack and a lot of this stuff here, so please bear with me if I did something dumb.

I used create-react-app (with eject) to make an app, and then according to the guide, I added the plugin

        new RazorPartialViewsWebpackPlugin({
          rules: [{
            // view for default chunk
            name: "main",
            template: {
              // Razor directive
              header: "@inherits System.Web.Mvc.WebViewPage"
            }
          }]
        })

If I run npm run build, this output:

> my-app@0.1.0 build C:\Users\gjudd\Documents\Develop\temp\my-app
> node scripts/build.js

Creating an optimized production build...
Failed to compile.

Cannot read property 'tap' of undefined

And if I run npm run start, this:

Starting the development server...

C:\Users\gjudd\Documents\Develop\temp\my-app\scripts\start.js:11
  throw err;
  ^

TypeError: Cannot read property 'assets' of undefined
    at Compilation.createModuleAssets (C:\Users\gjudd\Documents\Develop\temp\my-app\node_modules\webpack\lib\Compilation.js:4481:25)
    at C:\Users\gjudd\Documents\Develop\temp\my-app\node_modules\webpack\lib\Compilation.js:3051:13
    at C:\Users\gjudd\Documents\Develop\temp\my-app\node_modules\webpack\lib\Compilation.js:3276:6
    at Object.eachLimit (C:\Users\gjudd\Documents\Develop\temp\my-app\node_modules\neo-async\async.js:3461:14)
    at runIteration (C:\Users\gjudd\Documents\Develop\temp\my-app\node_modules\webpack\lib\Compilation.js:3205:13)
    at Compilation._runCodeGenerationJobs (C:\Users\gjudd\Documents\Develop\temp\my-app\node_modules\webpack\lib\Compilation.js:3280:3)
    at C:\Users\gjudd\Documents\Develop\temp\my-app\node_modules\webpack\lib\Compilation.js:3036:12
    at C:\Users\gjudd\Documents\Develop\temp\my-app\node_modules\webpack\lib\Compilation.js:3276:6
    at C:\Users\gjudd\Documents\Develop\temp\my-app\node_modules\neo-async\async.js:2818:7
    at done (C:\Users\gjudd\Documents\Develop\temp\my-app\node_modules\neo-async\async.js:3522:9)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app@0.1.0 start: `node scripts/start.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app@0.1.0 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:
npm ERR!     C:\Users\gjudd\AppData\Roaming\npm-cache\_logs\2022-03-15T21_20_31_322Z-debug.log

Any suggestions for how to proceed?

thanks, Gwyn

jouni-kantola commented 2 years ago

Hi @gwynjudd!

Thanks for reaching out.

I think your webpack.config.js is incorrectly configured. Make sure you put new RazorPartialViewsWebpackPlugin(...) to the correct plugins section (a pointer would be to look e.g. HtmlWebpackPlugin).

I believe this issue to be closely related to yours: https://github.com/webpack/webpack/issues/8548#issuecomment-449829774

  1. I was able to reproduce the error, because I was lucky to make (what I think was the same) mistake as you. I get TypeError: Cannot read property 'assets' of undefined when adding new RazorPartialViewsWebpackPlugin(...) to the wrong section of webpack.config.js.
  2. Once I moved new RazorPartialViewsWebpackPlugin(...) to plugins: [ ... ]`, Razor partial views are emitted as expected.
jouni-kantola commented 2 years ago

I'll close this issue, as the problem most likely is a webpack configuration error rather than a bug in the plugin.

gwynjudd commented 2 years ago

@jouni-kantola thanks yes that seems to have been the problem. Once I moved it to the correct location, all was working as expected