9

Executing This:

node .\node_modules\webpack\bin\webpack.js --config scripts/webpack.config.js --display-error-details

Produces this error.

I am just testing this at the moment, so application.ts just has this

export class Aureus {

    constructor() {
        alert('1');
    }

}

The webpack file looks as follows:

const globule = require("globule");
const path = require("path");
const webpack = require("webpack");
const extractTextPlugin = require("extract-text-webpack-plugin");

const config = {
};

const configuration = {
    context: __dirname,
    entry: {
        "application": 
            "application.ts",
            ...globule.find("aureus/**/*.ts", { srcBase: "./scripts" }),
        ,
        "vendor": [
            "bootstrap",
            "jquery",
            "angular",
            "moment",
            "lodash",
            "ramda",
        ],
    },
    output: {
        path: path.join(__dirname, "../"),
        filename: "packed.js"
    },
    devtool: "source-map",
    plugins: [
        new webpack.LoaderOptionsPlugin({
            debug: true
        }),
        new webpack.optimize.CommonsChunkPlugin({
            name: "vendor",
            filename: "vendor.js"
        }),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            "window.jQuery": "jquery",
            "window.jquery": "jquery",
        }),
    ],
    resolve:
    {
        alias: {
        }
    },
    module: {
        rules: [
            {
                test: /^((?!\.spec\.ts).)*.ts$/,
                use: [
                    {
                        loader: "awesome-typescript-loader"
                    }
                ],
                exclude: /(node_modules)/
            },
        ]
    }
};

module.exports = configuration;

I am getting this error? application.ts is in ./scripts/application.ts (same directory as webpack.config.js)

ERROR in Entry module not found: Error: Can't resolve 'application.ts' in 'C:\Projects\Github\Aureus\Aureus.Web\scripts'
resolve 'application.ts' in 'C:\Projects\Github\Aureus\Aureus.Web\scripts'
  Parsed request is a module
  using description file: C:\Projects\Github\Aureus\Aureus.Web\package.json (relative path: ./scripts)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: C:\Projects\Github\Aureus\Aureus.Web\package.json (relative path: ./scripts)
    resolve as module
      C:\Projects\Github\Aureus\Aureus.Web\scripts\node_modules doesn't exist or is not a directory
      C:\Projects\Github\Aureus\node_modules doesn't exist or is not a directory
      C:\Projects\Github\node_modules doesn't exist or is not a directory
      C:\Projects\node_modules doesn't exist or is not a directory
      C:\node_modules doesn't exist or is not a directory
      looking for modules in C:\Projects\Github\Aureus\Aureus.Web\node_modules
        using description file: C:\Projects\Github\Aureus\Aureus.Web\package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: C:\Projects\Github\Aureus\Aureus.Web\package.json (relative path: ./node_modules)
          using description file: C:\Projects\Github\Aureus\Aureus.Web\package.json (relative path: ./node_modules/application.ts)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              C:\Projects\Github\Aureus\Aureus.Web\node_modules\application.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              C:\Projects\Github\Aureus\Aureus.Web\node_modules\application.ts.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              C:\Projects\Github\Aureus\Aureus.Web\node_modules\application.ts.json doesn't exist
            as directory
              C:\Projects\Github\Aureus\Aureus.Web\node_modules\application.ts doesn't exist
Jim
  • 14,952
  • 15
  • 80
  • 167
  • 1
    did you fix this problem? I have a same problem but I still want to use @ in the import path. @Jim https://stackoverflow.com/questions/70902895/field-browser-doesnt-contain-a-valid-alias-configuration-when-i-changed-the-i – Dolphin Jan 29 '22 at 06:44

2 Answers2

11

Unless you provide an actual resolve rule, your imports of anything in the node_modules will default to looking in the folder provided to the context.

Try this rather:

resolve: {    
  modules: [
    /* assuming that one up is where your node_modules sit,
       relative to the currently executing script
    */
    path.join(__dirname, '../node_modules')
  ]
}

Also, make sure that you are referencing your entry relative to the context like so:

"application": "./application.ts"

instead of

"application": "application.ts"
Siya Mzam
  • 4,655
  • 1
  • 26
  • 44
  • This helps somewhat, but now I am finding that the globule included files are all being searched for in the node_modules folder. – Jim Dec 09 '17 at 06:07
  • no extension Field 'browser' doesn't contain a valid alias configuration D:\Development\Projects\AureusEx\Aureus.Web\node_modules\aureus\services\UrlParserService.ts doesn't exist – Jim Dec 09 '17 at 06:07
  • the paths here gave me the runaround big time... thanks for the tips. – Jim Dec 11 '17 at 08:19
  • Hey, sorry for the late reply. Did you manage to solve the problem? If so, how? You can edit my answer :). You're welcome – Siya Mzam Dec 11 '17 at 08:21
  • 1
    Your answer was spot on, helped a lot - thanks! I have multiple entry points and dependencies which made the paths tricky. I am transitioning from legacy js to weppack / es6 imports. – Jim Dec 11 '17 at 08:24
  • I can imagine. All the best with the task – Siya Mzam Dec 11 '17 at 10:58
1

Maybe you need to check your package-lock.json, and assumed that your package version is correct

NPM will give this error when your packages version in incorrect.

Here are three tips:

  1. Check Node version: node -v
  2. Make sure that you already install when you enter the root directory: nom i
  3. Check the version in package.json files. You may find some questions.

Like so:

"eslint": "^5.16.0",

Instead of:

"eslint": "^4.4.0",
wenxuan feng
  • 57
  • 1
  • 6