[webpack-cli] Error: Cannot find module 'tslib'
shahinghasemi opened this issue · 2 comments
shahinghasemi commented
Describe the bug
I want to dockerizing my app and in the build stage (webpack
) it throws this error:
[webpack-cli] Failed to load '/app/webpack.config.ts' config
[webpack-cli] Error: Cannot find module 'tslib'
Require stack:
- /app/webpack.config.ts
- /app/node_modules/webpack-cli/lib/webpack-cli.js
- /app/node_modules/webpack-cli/lib/bootstrap.js
- /app/node_modules/webpack-cli/bin/cli.js
- /app/node_modules/webpack/bin/webpack.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (/app/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at Object.<anonymous> (/app/webpack.config.ts:3:17)
at Module._compile (/app/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Module.m._compile (/app/node_modules/ts-node/src/index.ts:1225:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Object.require.extensions.<computed> [as .ts] (/app/node_modules/ts-node/src/index.ts:1228:12)
at Module.load (internal/modules/cjs/loader.js:928:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/app/webpack.config.ts',
'/app/node_modules/webpack-cli/lib/webpack-cli.js',
'/app/node_modules/webpack-cli/lib/bootstrap.js',
'/app/node_modules/webpack-cli/bin/cli.js',
'/app/node_modules/webpack/bin/webpack.js'
]
}
What is the current behavior?
Throwing error on the build stage
To Reproduce
Steps to reproduce the behavior:
webpack.config.ts
import path from 'path';
import { Configuration } from 'webpack';
const isProduction = process.env.NODE_ENV === 'production';
const wpConfig: Configuration = {
entry: path.resolve(__dirname, './src/main.ts'),
output: {
filename: 'main.js',
path: path.resolve(__dirname, './build'),
library: {
type: 'commonjs',
},
},
mode: isProduction ? 'production' : 'development',
target: 'node14.15',
node: {
__dirname: true,
__filename: true,
},
externals: /k6(\/.*)?/,
stats: 'errors-only',
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /\.ts$/,
use: ['babel-loader'],
exclude: /node_modules/,
},
],
},
};
export default wpConfig;
package.json
{
"name": "testing",
"version": "1.0.0",
"description": "load testing project",
"main": "./src/main.ts",
"scripts": {
"type-check": "tsc",
"build-wp": "webpack",
"build": "yarn type-check && yarn build-wp",
"test": "k6 run build/main.js",
"k6:go": "yarn build && yarn test"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/preset-typescript": "^7.14.5",
"@types/k6": "^0.32.2",
"@types/node": "^16.3.3",
"@types/webpack": "^5.28.0",
"babel-loader": "^8.2.2",
"ts-node": "^10.1.0",
"typescript": "^4.3.5",
"webpack": "^5.44.0",
"webpack-cli": "^4.7.2"
},
"dependencies": {}
}
Dockerfile
FROM node:14.15.4-alpine as build
# add node-gyp build dependencies & upgrade npm
RUN apk update && \
apk add --no-cache python make g++ curl git && \
npm i -g npm
WORKDIR /app
COPY babel.config.js tsconfig.json webpack.config.ts ./
COPY package.json yarn.lock ./
RUN yarn install
COPY src ./src/
RUN yarn build
tsconfig.json
{
"include": ["webpack.config.ts", "src/**/*"],
"exclude": ["node_modules"],
"compilerOptions": {
// Target ECMAScript.
"target": "ES6",
"importHelpers": true,
// Search under node_modules for non-relative imports.
"moduleResolution": "node",
"module": "CommonJS",
// Process & infer types from .js files.
"allowJs": true,
// Don't emit; allow Babel to transform files.
"noEmit": true,
// Enable strictest settings like strictNullChecks & noImplicitAny.
"strict": true,
// Disallow features that require cross-file information for emit.
"isolatedModules": true,
// Import non-ES modules as default imports.
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
},
}
docker build -t sometag . will create the mentioned error.
Expected behavior
Building the application successfully
Additional context
If I comment out importHelpers
the error will be gone, but don't know why!
thanks in advance.
alexander-akait commented
Please install tslib
- npm install -D tslib
shahinghasemi commented
Thanks, thought it's included in typescript
package.