Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

[aspnet-webpack] invalid argument since 1.0.19 #408

Closed

Description

@JanEggers

Hi im getting the following error since updating to 1.0.19 before it was fine.

the path which causes the problem is \wwwroot

Microsoft.AspNetCore.NodeServices: Error: Unhandled rejection Error: invalid argument
at pathToArray (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\memory-fs\lib\MemoryFileSystem.js:44:10)
at MemoryFileSystem.meta (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\memory-fs\lib\MemoryFileSystem.js:61:13)
at MemoryFileSystem.statSync (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\memory-fs\lib\MemoryFileSystem.js:76:21)
at D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\aspnet-webpack\WebpackDevMiddleware.js:97:33
at Array.forEach (native)
at copyRecursiveSync (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\aspnet-webpack\WebpackDevMiddleware.js:93:31)
at Compiler. (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\aspnet-webpack\WebpackDevMiddleware.js:79:9)
at Compiler.applyPlugins (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\tapable\lib\Tapable.js:26:37)
at Watching._done (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compiler.js:78:17)
at Watching. (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compiler.js:61:18)
at Compiler.emitRecords (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compiler.js:282:37)
at Watching. (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compiler.js:58:19)
at D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compiler.js:275:11
at Compiler.applyPluginsAsync (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\tapable\lib\Tapable.js:60:69)
at Compiler.afterEmit (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compiler.js:272:8)
at Compiler. (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compiler.js:267:14)
From previous event:
at Compiler. (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\html-webpack-plugin\index.js:197:15)
at Compiler.applyPluginsAsync (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\tapable\lib\Tapable.js:71:13)
at Compiler.emitAssets (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compiler.js:226:7)
at Watching. (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compiler.js:54:18)
at D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compiler.js:403:12
at Compiler.next (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\tapable\lib\Tapable.js:67:11)
at Compiler. (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\awesome-typescript-loader\src\instance.ts:471:9)
at Compiler.next (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\tapable\lib\Tapable.js:69:14)
at Compiler. (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\CachePlugin.js:40:4)
at Compiler.applyPluginsAsync (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\tapable\lib\Tapable.js:71:13)
at Compiler. (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compiler.js:400:9)
at Compilation. (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compilation.js:577:13)
at Compilation.applyPluginsAsync (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\tapable\lib\Tapable.js:60:69)
at Compilation. (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compilation.js:572:10)
at Compilation.applyPluginsAsync (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\tapable\lib\Tapable.js:60:69)
at Compilation. (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compilation.js:567:9)
at Compilation.applyPluginsAsync (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\tapable\lib\Tapable.js:60:69)
at Compilation. (D:\Repositories\Maintenance Web App\src\Maintenance.Web\node_modules\webpack\lib\Compilation.js:563:8)

Activity

  1. JanEggers commented on Oct 27, 2016

    @JanEggers
    Author

    here the config:

    webpack.common.js:

    var webpack = require('webpack');
    var HtmlWebpackPlugin = require('html-webpack-plugin');
    module.exports = {
      entry: {
        'polyfills': './wwwroot/app/polyfills.ts',
        'vendor': './wwwroot/app/vendor.ts',
        'app': './wwwroot/app/main.ts'
      },
      resolve: {
        // Try .ts first, otherwise map will reference .js file.
        extensions: ['', '.ts', '.js','.json', '.css', '.less', '.html']
      },
      module: {
        loaders: [
          {
              test: /\.ts$/,
              loaders: ['awesome-typescript', 'angular2-template', '@angularclass/hmr-loader']
          },
          {
              test: /\.html$/,
              loader: 'html'
          },
          {
              test: /\.(png|jpe?g|gif|svg|woff2|woff|ttf|eot|ico)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
              loader: 'file?name=assets/[name].[hash].[ext]'
          },
          {
              test: /\.less$/,
              exclude: /node_modules/,
              loader: 'raw!less'
          }
        ]
      },
      plugins: [
        new webpack.optimize.CommonsChunkPlugin({
            names: ['app', 'vendor', 'polyfills'],
            minChunks: Infinity
        }),
        new HtmlWebpackPlugin({
          template: './wwwroot/index.html'
        }),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            jquery: 'jquery'
        })
      ]
    };
    

    webpack.dev.js:

    var webpackMerge = require('webpack-merge');
    var commonConfig = require('./webpack.common.js');
    module.exports = webpackMerge(commonConfig, {
        devtool: 'source-map',
        output: {
            path: '/wwwroot/bundles',
            publicPath: '/bundles/',
            filename: '[name].js',
            chunkFilename: '[id].chunk.js'
        },
        devServer: {
            historyApiFallback: true,
            stats: 'minimal'
        }
    });
    
  2. MarkPieszak commented on Oct 27, 2016

    @MarkPieszak
    Contributor

    @JanEggers You can see the error steaming from:
    Error: Unhandled rejection Error: invalid argument at pathToArray

    I believe it's coming from

    output: {
            path: , // <-- 
    

    It should be: path: path.join( __dirname, '/wwwroot/bundles' )

  3. JanEggers commented on Oct 27, 2016

    @JanEggers
    Author

    the configuration i have is correct. it is working with webpack devserver or aspnet-webpack < 1.0.19

    the error is thrown at a row that validates a regex that does not accept \ and i dont have \ in my config so it must be some internal path stuff of aspnet-webpack

  4. SteveSandersonMS commented on Oct 27, 2016

    @SteveSandersonMS
    Member

    There was an issue in path handling on version 1.0.19, which was since fixed in 1.0.20. Can you let us know whether you still encounter the problem in the latest version of aspnet-webpack (1.0.21)?

  5. JanEggers commented on Oct 27, 2016

    @JanEggers
    Author

    yep 1.0.21 gives the same error. any advices how i could isoate the source of the error?

  6. SteveSandersonMS commented on Oct 28, 2016

    @SteveSandersonMS
    Member

    I know you've mentioned that your webpack config is correct and works with webpack devserver, but it really doesn't look right. I suspect it might have only worked in the past because you're using an older version of webpack-dev-middleware (i.e., 1.8.1 or below) that allows some things to work almost by mistake even though they are ambiguous. Since version 1.8.2/1.8.3, webpack-dev-middleware introduces a stronger check that output.path is absolute, accounting for Win/*nix path differences.

    Your specification path: '/wwwroot/bundles' is an absolute path in Linux terms (and it's almost certainly not where you want to write your output), but doesn't have any clear meaning on a Windows system (and I see you are running Windows). For your webpack config to be correct as far as webpack-dev-middleware version 1.8.2+ is concerned, you absolutely must specify an absolute path for output.path, or you'll get this error:

    `output.path` needs to be an absolute path or `/`.
    

    Once you fix that aspect of your config, I suspect the error will go away. Roughly as @MarkPieszak mentioned, you can fix it by changing the config to:

    path: path.join(__dirname, './wwwroot/bundles' )
    

    To avoid this problem coming up for others in the future, I'm changing aspnet-webpack to take a dependency on webpack-dev-middleware 1.8.3+ (previously it only required 1.6.1+), so there should be a clearer error message if you don't supply an absolute path for output.path.

    Please let us know if this resolves the issue for you!

  7. JanEggers commented on Oct 28, 2016

    @JanEggers
    Author

    now that is interesting:

    if i change the ouput.path and stay on version 1.0.18 it works.

    but if i update to 1.0.21 i get the following error:

    Microsoft.AspNetCore.NodeServices: Error: Error: ENOENT: no such file or directory, open 'D:\Repositories\Maintenance Web App\src\Maintenance.Web\wwwroot\bundles\assets\summarizer.7d4eb4e532b05499591f6aa06632e072.png'
    at Error (native)

    the path is correct / as it was in version 1.0.18

    the file is not present (but it wasnt either with 1.0.18)

    any ideas?

  8. SteveSandersonMS commented on Oct 28, 2016

    @SteveSandersonMS
    Member

    I tried to reproduce your issue (using loader: 'file?name=assets/[name].[hash].[ext]' for an image, and running it on Windows from a directory where one of the parents has a space in its name) but no such problem occurred. It worked fine.

    So I'm afraid I don't know what's going on with your setup. Also I don't know how to interpret some of your statements:

    the path is correct / as it was in version 1.0.18

    As in, you've fixed it so it doesn't have the leading slash? Or you've left the leading slash in place? It should not have a leading slash, as described earlier.

    the file is not present (but it wasnt either with 1.0.18)

    So was it working on 1.0.18 or not? I'm not sure how it could be working if the .png file was not present.

    In order to investigate the further, I'd need to be able to reproduce the issue. If you're able to supply a minimal repro case (as in, starting with something like the Angular2Spa template, how to modify it to trigger the issue you've described) then I'll certainly be able to track it down.

  9. JanEggers commented on Oct 28, 2016

    @JanEggers
    Author

    So was it working on 1.0.18 or not?

    it was working but it seems no files where written to disk and only served from in memory

    ill try to create a repro next week. have a nice weekend.

  10. JanEggers commented on Oct 31, 2016

    @JanEggers
    Author

    hi there i didnt create a repro but i found the error by adding logging.

    1. in copyRecursiveSync you use writeFile without callback swallowing all the errors either add a callback or use the writeFileSync method.
    2. if the root output directory is not existing it wont be created and no files are written to disk. i added that and now its working fine again

    here is the modified copy version:

    function copyRecursiveSync(from, to, rootDir, exclude) {
        from.readdirSync(rootDir).forEach(function (filename) {
            var fullPath = pathJoinSafe(rootDir, filename);
            var shouldExclude = exclude.filter(function (re) { return re.test(fullPath); }).length > 0;
            if (!shouldExclude) {
                console.log('copy', fullPath, 'exclude', shouldExclude );
                var fileStat = from.statSync(fullPath);
                if (fileStat.isFile()) {
                    var fileBuf = from.readFileSync(fullPath);
                    to.writeFile(fullPath, fileBuf, function (err) {
                        console.log(to, fullPath, fileBuf.length, 'err', err );                    
                    });
                }
                else if (fileStat.isDirectory()) {
                    if (!fs.existsSync(fullPath)) {
                        fs.mkdirSync(fullPath);
                    }
                    copyRecursiveSync(from, to, fullPath, exclude);
                }
            }
        });
    }
    

    if a pr is wellcome i'll add one

  11. SteveSandersonMS commented on Oct 31, 2016

    @SteveSandersonMS
    Member

    Thanks @JanEggers for tracking this down! I've now published aspnet-webpack version 1.0.23 which includes your fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions