webpack - webpack.config.js - import path from "path"; ^^^^^^ SyntaxError: Cannot use import statement outside a module

 I was trying different ways to exclude node_modules / external libraries from being include / packaged together in my dist folder. So i tried out this settings 

webpack.config.js 

import path from "path";
import { Configuration } from "webpack";

const config: Configuration = {
  entry: "./src/index.ts",

To resolve this error, I had to go back to the good old webpack.config.js that look something like this


const path = require('path');
var nodeExternals = require('webpack-node-externals');

module.exports = {
  entry: './src/index.ts',
  target: 'node', // use require() & use NodeJs CommonJS style
  externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
  externalsPresets: {
      node: true // in order to ignore built-in modules like path, fs, etc.
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
  },
  output: {
    filename: 'index.js',
    path: path.resolve(__dirname, 'dist'),
  },
};





Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm