zuroslav
zuroslav

Reputation: 337

Cannot find namespace 'Webpack' during Aurelia application build with Webpack

I am trying to set up an Aurelia application with Webpack, but I get the error all the time:

[at-loader] Checking finished with 1 errors
[at-loader] ./node_modules/aurelia-loader-webpack/dist/commonjs/aurelia-loader-webpack.d.ts:31:51
    TS2503: Cannot find namespace 'Webpack'.

I installed @types/webpack and also modules: webpack, webpack-dev-server, webpack-dev-middleware and webpack-hot-middleware. I tried everything I could find, but nothing works, I am stuck.

This is my tsconfig:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "sourceRoot": "src",
    "allowJs": true,
    "baseUrl": "src",
    "lib": [
      "es2017", "dom"
    ]
  },
  "exclude": [
    "node_modules",
    "dist",
    "static"
  ],
  "typeAcquisition": {
    "include": [
      "src"
    ]
  }
}

I saw that people have similar problems with modules and namespaces, but not a single answer was working for me. Anyone has an idea what might be the problem?

Upvotes: 2

Views: 987

Answers (2)

Ph. Wiget
Ph. Wiget

Reputation: 151

As we could not tackle the problem nicely and because this error was preventing us from creating successful builds, we ended up by simple deleting the relevant declaration file (node_modules/aurelia-loader-webpack/dist/commonjs/aurelia-loader-webpack.d.ts).

I know this is not the preferred solution, however it works and it shouldn't be of any problem, as the node_modules directory should anyway be ignored by the awesome-typescript-loader. Some how it wasn't.

Upvotes: 1

Doug Kent
Doug Kent

Reputation: 855

You can compare to a Webpack/Aurelia setup that works.

Here is a sequence of windows console commands that easily create such a skeleton. Note it works with .NET though, which may not match your needs. But it should be possible to simplify the resulting skeleton to work without the .Net parts.

Steps:

dotnet new --install Microsoft.AspNetCore.SpaTemplates::*
mkdir [Your Project Folder]
cd [Your Project Folder]
dotnet new aurelia
dotnet restore
npm install

Set an environment variable to tell ASP.NET to run in development mode:

  • If you’re using PowerShell in Windows, execute $Env:ASPNETCORE_ENVIRONMENT = "Development"

  • If you’re using cmd.exe in Windows, execute setx ASPNETCORE_ENVIRONMENT "Development", and then restart your command prompt to make the change take effect

  • If you’re using Mac/Linux, execute export ASPNETCORE_ENVIRONMENT=Development

Finally:

dotnet run

Upvotes: 0

Related Questions