-
Notifications
You must be signed in to change notification settings - Fork 70
Description
What happens and why it is wrong
A runtime error occurs when your tsconfig.json has "declarationMap": true and you use this plugin as a configPlugin.
Per the error below, it occurs on this line in the code. Specifically, it appears that declarationDir is undefined because in the case of a configPlugin, Rollup's output isn't set what-so-ever, so output.file and output.dir are both undefined (see below for verbosity that verifies this).
Ironically, I actually wrote this code myself in #221 so I could write a PR to fix this myself. I think a default declarationDir equivalent to cwd would probably suffice for this -- let me know if you think a different solution makes sense, otherwise I could write that up pretty quickly.
To be specific, rpts2 only errors when declarationMap is turned on, everything else doesn't seem to be impacted, so things like emitFile etc still work when used as a configPlugin.
Current workaround is to disable declarationMap in tsconfig (or tsconfigOverrides) specifically when using as a configPlugin only.
Error:
$ rollup -c rollup.config.ts --configPlugin rollup-plugin-typescript2
[!] (plugin rpt2) TypeError: The "from" argument must be of type string. Received undefined
TypeError [ERR_INVALID_ARG_TYPE]: The "from" argument must be of type string. Received undefined
at new NodeError (internal/errors.js:322:7)
at validateString (internal/validators.js:124:11)
at Object.relative (path.js:1167:5)
at <project>/node_modules/rollup-plugin-typescript2/src/index.ts:383:25
at Array.map (<anonymous>)
at emitDeclaration (<project>/node_modules/rollup-plugin-typescript2/src/index.ts:380:47)
at <project>/node_modules/rollup-plugin-typescript2/src/index.ts:401:5
at <project>/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:4967:15
at baseForOwn (<project>/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:3032:24)
at <project>/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:4936:18Environment
Versions
npmPackages:
rollup: ^2.70.2 => 2.70.2
rollup-plugin-typescript2: ^0.31.2 => 0.31.2
typescript: ^4.6.3 => 4.6.3
rollup.config.ts
:
rollup.config.tsMy rollup config actually isn't relevant as I'm actually not using rpts2 in the rollup config, just for parsing the config itself (as I wrote it in TS)
tsconfig.json
:
tsconfig.json(slightly simplified version as I actually have multiple tsconfigs that extend each other)
{
// only build the rollup config for this parse through
"files": ["rollup.config.ts"],
// https://github.com/tsconfig/bases
"extends": "@tsconfig/strictest/tsconfig.json",
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"compilerOptions": {
// output to dist/ dir
"outDir": "dist/",
// output .d.ts declaration files for consumers
"declaration": true,
// output .d.ts.map declaration map files for consumers
"declarationMap": true,
// output .js.map sourcemap files for consumers
"sourceMap": true,
// use Node's module resolution algorithm, instead of the legacy TS one
"moduleResolution": "node",
// resolve JSON files
"resolveJsonModule": true,
// transpile JSX to React.createElement
"jsx": "react",
// ignored during builds, but commonly used when type-checking with `tsc`
"noEmit": true,
}
}package.json
:
package.jsonThink the envinfo output above is good enough; I've found the error in any case.
plugin output with verbosity 3
:
rpt2: built-in options overrides: {
"noEmitHelpers": false,
"importHelpers": true,
"noResolve": false,
"noEmit": false,
"inlineSourceMap": false,
"outDir": "<project>/node_modules/.cache/rollup-plugin-typescript2/placeholder",
"moduleResolution": 2,
"allowNonTsExtensions": true,
"module": 5
}
rpt2: parsed tsconfig: {
"options": {
"strict": true,
"allowUnusedLabels": false,
"allowUnreachableCode": false,
"exactOptionalPropertyTypes": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"importsNotUsedAsValues": 2,
"checkJs": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "<project>/node_modules/.cache/rollup-plugin-typescript2/placeholder",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"moduleResolution": 2,
"resolveJsonModule": true,
"jsx": 2,
"noEmit": false,
"configFilePath": "<project>/tsconfig.json",
"noEmitHelpers": false,
"importHelpers": true,
"noResolve": false,
"inlineSourceMap": false,
"allowNonTsExtensions": true,
"module": 5
},
"fileNames": [
"<project>/rollup.config.ts"
],
"typeAcquisition": {
"enable": false,
"include": [],
"exclude": []
},
"raw": {
"extends": "@tsconfig/strictest/tsconfig.json",
"exclude": [
"node_modules/",
"dist/",
"coverage/",
"example/"
],
"compilerOptions": {
"outDir": "dist/",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"jsx": "react",
"noEmit": true
},
"files": [
"rollup.config.ts"
],
"compileOnSave": false
},
"errors": [],
"wildcardDirectories": {},
"compileOnSave": false
}
rpt2: typescript version: 4.6.3
rpt2: tslib version: 2.3.1
rpt2: rollup version: 2.70.2
rpt2: rollup-plugin-typescript2 version: 0.31.2
rpt2: plugin options:
{
"verbosity": 3,
"check": true,
"clean": false,
"cacheRoot": "<project>/node_modules/.cache/rollup-plugin-typescript2",
"include": [
"*.ts+(|x)",
"**/*.ts+(|x)"
],
"exclude": [
"*.d.ts",
"**/*.d.ts"
],
"abortOnError": true,
"rollupCommonJSResolveHack": false,
"useTsconfigDeclarationDir": false,
"transformers": [],
"tsconfigDefaults": {},
"objectHashIgnoreUnknownHack": false,
"cwd": "<project>",
"typescript": "version 4.6.3"
}
rpt2: rollup config:
{
"input": "<project>/rollup.config.ts",
"plugins": [
{
"name": "rpt2"
}
],
"treeshake": false
}
rpt2: tsconfig path: <project>/tsconfig.json
rpt2: included:
[
"*.ts+(|x)",
"**/*.ts+(|x)"
]
rpt2: excluded:
[
"*.d.ts",
"**/*.d.ts"
]
rpt2: Ambient types:
rpt2: <project>/node_modules/@types/babel__core/index.d.ts
rpt2: <project>/node_modules/@types/babel__generator/index.d.ts
rpt2: <project>/node_modules/@types/babel__template/index.d.ts
rpt2: <project>/node_modules/@types/babel__traverse/index.d.ts
rpt2: <project>/node_modules/@types/cheerio/index.d.ts
rpt2: <project>/node_modules/@types/enzyme/index.d.ts
rpt2: <project>/node_modules/@types/estree/index.d.ts
rpt2: <project>/node_modules/@types/graceful-fs/index.d.ts
rpt2: <project>/node_modules/@types/istanbul-lib-coverage/index.d.ts
rpt2: <project>/node_modules/@types/istanbul-lib-report/index.d.ts
rpt2: <project>/node_modules/@types/istanbul-reports/index.d.ts
rpt2: <project>/node_modules/@types/json5/index.d.ts
rpt2: <project>/node_modules/@types/node/ts3.2/index.d.ts
rpt2: <project>/node_modules/@types/parse-json/index.d.ts
rpt2: <project>/node_modules/@types/prettier/index.d.ts
rpt2: <project>/node_modules/@types/prop-types/index.d.ts
rpt2: <project>/node_modules/@types/react/index.d.ts
rpt2: <project>/node_modules/@types/resolve/index.d.ts
rpt2: <project>/node_modules/@types/scheduler/index.d.ts
rpt2: <project>/node_modules/@types/signature_pad/index.d.ts
rpt2: <project>/node_modules/@types/stack-utils/index.d.ts
rpt2: <project>/node_modules/@types/yargs/index.d.ts
rpt2: <project>/node_modules/@types/yargs-parser/index.d.ts
rpt2: ambient types changed, redoing all semantic diagnostics
rpt2: transpiling '<project>/rollup.config.ts'
rpt2: cache: '<project>/node_modules/.cache/rollup-plugin-typescript2/rpt2_886b5474ceab46316c300049e28ace720638ad6b/code/cache/8ff12b6a0f6d14ec54898a8a47dd4d86c8c3c981'
rpt2: cache miss
rpt2: cache: '<project>/node_modules/.cache/rollup-plugin-typescript2/rpt2_886b5474ceab46316c300049e28ace720638ad6b/syntacticDiagnostics/cache/8ff12b6a0f6d14ec54898a8a47dd4d86c8c3c981'
rpt2: cache miss
rpt2: cache: '<project>/node_modules/.cache/rollup-plugin-typescript2/rpt2_886b5474ceab46316c300049e28ace720638ad6b/semanticDiagnostics/cache/8ff12b6a0f6d14ec54898a8a47dd4d86c8c3c981'
rpt2: cache miss
rpt2: generated declarations for '<project>/rollup.config.ts'
rpt2: generating target 1
rpt2: rolling caches
rpt2: emitting declarations for '<project>/rollup.config.ts' to 'rollup.config.d.ts'
[!] (plugin rpt2) TypeError: The "from" argument must be of type string. Received undefined
TypeError [ERR_INVALID_ARG_TYPE]: The "from" argument must be of type string. Received undefined
at new NodeError (internal/errors.js:322:7)
at validateString (internal/validators.js:124:11)
at Object.relative (path.js:1167:5)
at <project>/node_modules/rollup-plugin-typescript2/src/index.ts:383:25
at Array.map (<anonymous>)
at emitDeclaration (<project>/node_modules/rollup-plugin-typescript2/src/index.ts:380:47)
at <project>/node_modules/rollup-plugin-typescript2/src/index.ts:401:5
at <project>/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:4967:15
at baseForOwn (<project>/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:3032:24)
at <project>/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:4936:18