W
W
Wasya UK2017-10-18 18:16:35
JavaScript
Wasya UK, 2017-10-18 18:16:35

Why doesn't webpack.config.ts find __dirname?

The config/ folder contains the webpack.config.ts file , I run it with webpack.config.js :

require('ts-node').register({
  project: 'tsconfig.tsnode.json'
});

module.exports = require('./config/webpack.config').default;

But I get
implicitly has an 'any' type.
Try `npm install @types/webpack` if it exists or add a new declaration (.d.ts) file containing `declare module 'webpack';` (7016)
config\webpack.config.ts (4,38): Cannot find name '__dirname'. (2304)

PS d.ts did not help
How to write correctly? Thanks in advance:
import * as path from "path";
import * as webpack from "webpack";

const projectRootPath = path.resolve(__dirname, '../');

const config = webpack.Configuration = {
  context: path.resolve(__dirname, '..'),
  entry: ["./src/app.tsx"],
  output: {
    filename: "bundle.js",
    path: path.resolve(__dirname, './public/js'),
    publicPath: path.resolve(__dirname, '/public/')
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        exclude: '/node_modules/',
        use: {
          loader: "ts",
          presets: ['react']
        }
      }
    ]
  },
  resolve: {
    extensions: ["*", ".webpack.js", ".jsx", ".ts", ".tsx", ".js"]
  },
  watch: true
};

export default config;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2017-10-18
@k12th

npm install @types/nodeseems like it should help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question