azure-pipelines-task-lib: Cannot use JS bundler because of shelljs dependency
Please check our current Issues to see if someone already reported this https://github.com/Microsoft/azure-pipelines-task-lib/issues
Environment
azure-pipelines-task-lib version: 4.3.1
Issue Description
JavaScript tasks cannot be bundled using a library like rollup or esbuild because shelljs does not explicitely declare its dependencies: https://github.com/shelljs/shelljs/issues/962
There is currently a pull-request open on shelljs to address the issue, but it hasn’t moved since March https://github.com/shelljs/shelljs/pull/1119
Currently, the best way I found to circumvent this is to create a bundler plugin to replace the /node_modules/shelljs/shell.js file with the fixed file at compile-time.
Expected behaviour
I can bundle a task using a popular bundler like rollup or esbuild with the target platform set to node.
Actual behaviour
The task will build but most shelljs files will be missing from the bundle.
There will be a runtime exception when trying to run the task due to missing dependencies that only resolve at runtime.
Steps to reproduce
Using esbuild:
- Add
esbuildas a devDependency:
npm i --D esbuild
- Create a
build.mjsfile with this content:
import * as esbuild from 'esbuild'
await esbuild.build({
entryPoints: ['./src/index.js'], // or whatever your entryfile is...
outfile: './dist/index.js',
bundle: true,
platform: "node",
target: "node16",
allowOverwrite: true,
});
- Run the build:
node build.mjs
- Run the task:
node dist/index.js
- An error message should appear.
Logs
$ node dist/index.js
node:internal/modules/cjs/loader:1029
throw err;
^
Error: Cannot find module './src/cat'
Require stack:
- /dist/index.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1026:15)
at Function.Module._load (node:internal/modules/cjs/loader:871:27)
at Module.require (node:internal/modules/cjs/loader:1098:19)
at require (node:internal/modules/cjs/helpers:108:18)
at /dist/index.js:2807:7
at Array.forEach (<anonymous>)
at node_modules/shelljs/shell.js (/dist/index.js:2806:24)
at __require (/dist/index.js:12:52)
at node_modules/azure-pipelines-task-lib/task.js (/dist/index.js:7287:17)
at __require (/dist/index.js:12:52) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/dist/index.js'
]
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 15 (4 by maintainers)
Hi @tjosepo thanks for reporting! We are working on more prioritized issues at the moment, but will get back to this one soon.