s-panferov / awesome-typescript-loader

Awesome TypeScript loader for webpack
Other
2.35k stars 181 forks source link

Error : Critical dependency: require function is used in a way in which dependencies cannot be statically extracted #613

Open neilime opened 5 years ago

neilime commented 5 years ago

Hi,

I got an error when I try to run webpack and awesome-typescript-loader, to package a typescript serverless function, with a dependency package named 'imagemin-jpegtran'.

Edit : this error occurs because of bin-wrapper module which is using require('import-lazy')(require); https://github.com/kevva/bin-wrapper/blob/master/index.js#L5

I hope somebody will be able to help me because I've tried so many different ways but always unsuccessfull...

Thank you

package.json

{
  "name": "test-jpegtran-bin",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "imagemin-jpegtran": "^5.0.2"
  },
  "devDependencies": {
    "@types/imagemin-jpegtran": "^5.0.0",
    "@types/node": "^10.11.6",
    "@types/webpack": "^4.4.16",
    "awesome-typescript-loader": "^5.2.1",
    "source-map-loader": "^0.2.4",
    "ts-node": "^7.0.1",
    "typescript": "^3.1.2",
    "webpack": "^4.20.2",
    "webpack-cli": "^3.1.2"
  },
  "scripts": {
    "start": "webpack"
  },
  "author": "",
  "license": "ISC"
}

webpack.config.js

module.exports = {
    mode: 'production',
    entry: "./src/index.ts",
    output: {
        filename: "bundle.js",
        path: __dirname + "/dist"
    },
    devtool: "source-map",
    resolve: {
        extensions: [".ts", ".tsx", ".js", ".json"]
    },
    target: 'node',
    module: {
        rules: [
            { test: /\.tsx?$/, loader: "awesome-typescript-loader" },
        ]
    },
};

tsconfig.json

{
    "compilerOptions": {
        "outDir": "./dist/",
        "sourceMap": true,
        "noImplicitAny": true,
        "module": "commonjs",
        "target": "es5",
        "lib": [
            "es6"
        ]
    },
    "include": [
        "./src/**/*"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}

src/index.ts

import * as  imageminJpegtran from 'imagemin-jpegtran';
imageminJpegtran();

Stacktrace

webpack

ℹ 「atl」: Using typescript@3.1.2 from typescript ℹ 「atl」: Using tsconfig.json from .../test-jpegtran-bin/tsconfig.json ℹ 「atl」: Checking started in a separate process... ℹ 「atl」: Time: 533ms Hash: d7a480ae3053cb681e38 Version: webpack 4.20.2 Time: 4169ms Built at: 2018-10-10 18:26:58 Asset Size Chunks Chunk Names bundle.js 69.2 KiB 0 [emitted] main bundle.js.map 270 KiB 0 [emitted] main Entrypoint main = bundle.js bundle.js.map [0] external "fs" 42 bytes {0} [built] [1] external "path" 42 bytes {0} [built] [2] external "util" 42 bytes {0} [built] [3] external "assert" 42 bytes {0} [built] [6] external "child_process" 42 bytes {0} [built] [11] external "events" 42 bytes {0} [built] [19] ./src/index.ts 54 bytes {0} [built] [44] external "stream" 42 bytes {0} [built] [62] external "crypto" 42 bytes {0} [built] [65] external "os" 42 bytes {0} [built] [71] ./node_modules/bin-wrapper sync 160 bytes {0} [built]

  • 62 hidden modules

WARNING in ./node_modules/bin-wrapper/index.js 5:34-41 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted @ ./node_modules/jpegtran-bin/lib/index.js @ ./node_modules/jpegtran-bin/index.js @ ./node_modules/imagemin-jpegtran/index.js @ ./src/index.ts