TrilonIO / aspnetcore-Vue-starter

*NEW* Asp.net Core & Vue.js (ES6) SPA Starter kit - Vuex, webpack, Web API, Docker, and more! By @TrilonIO
https://www.trilon.io
MIT License
1.22k stars 266 forks source link

Error running webpack #21

Closed stibay closed 7 years ago

stibay commented 7 years ago

After cloning and running yarn I am getting this error when running webpack:

Error: Cannot find module './wwwroot/dist/vendor-manifest.json'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at module.exports (C:\Users\..\webpack.config.js:40:27)
    at requireConfig (C:\Users\..\AppData\Roaming\npm\node_modules\webpack\bin\convert-argv.js:102:15)
    at C:\Users\..\AppData\Roaming\npm\node_modules\webpack\bin\convert-argv.js:109:17
    at Array.forEach (native)
    at module.exports (C:\Users\..\AppData\Roaming\npm\node_modules\webpack\bin\convert-argv.js:107:15)
    at Object.<anonymous> (C:\Users\..\AppData\Roaming\npm\node_modules\webpack\bin\webpack.js:153:40)
MarkPieszak commented 7 years ago

We had some big updates the past few days! Think we need to add the postinstall script back that installs the vendor bundle.

Can you run the vendor pack, then regular webpack should work.

webpack --config webpack.config.vendor.js 

Let us know!

anderly commented 7 years ago

I ran into this as well when I recently cloned to a new machine. The main repo has had this issue as well: https://github.com/aspnet/JavaScriptServices/issues/99

Although, I think this new section in the .csproj should address it:

<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec Command="npm install" />
    <Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
    <Exec Command="node node_modules/webpack/bin/webpack.js --env.prod" />

    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="wwwroot\dist\**; ClientApp\dist\**" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>

I'll try a fresh clone to confirm.

vip32 commented 7 years ago

i also noticed this build issue this will fix it:

webpack --config webpack.config.vendor.js 

after that 'dotnet run dev' should work

however the csproj change does not try to build the vendor.js at the moment how should that 'RunWebpack' target be executed, through 'dotnet run prod'?

anderly commented 7 years ago

Right now, the RunWebpack target gets executed prior to publish. We could either add a script to package.json or have that target execute as part of the default build/compile. See also: https://github.com/JohannesHoppe/angularCore/commit/b5b759a55164c6972e467bf66dccdc76e26e74ec

MarkPieszak commented 7 years ago

@stibay Did you give that command a shot?

stibay commented 7 years ago

Yes, thank you. That fixed it.

vip32 commented 7 years ago

However, we still need to fix this in the build though @stibay can you please reopen?

cjblomqvist commented 7 years ago

Fixes the issue. The only downside is that it'll build the vendor files twice when publishing. First one time dev-style and then rebuilds the files one time prod-style, which means the prod-style files will always be the ones being used.

The only other way is to hack inside the csproj-file to dynamically run the vendor building without the prod flag, and also exclude all the other things being run. Not sure if this is doable, I'm unfortunately some what of a noob when it comes to .NET but is seems to be much more complicated. Unless you have a huge amount of vendor files, this shouldn't be a huge issue since the build time penalty should be quite small.