Module resolution: noUncheckedSideEffectImports doesn't resolve CSS-only node_modules with globals.d.ts
Closed this issue · 6 comments
Demo Repo
https://github.com/jdufresne/typescript-nouncheckedsideeffectimports
Which of the following problems are you reporting?
The module specifier resolves to the right file, but something about the types are wrong
Demonstrate the defect described above with a code sample.
globals.d.ts:
declare module "*.css";index.ts:
import "@fontsource/roboto";Run tsc --showConfig and paste its output here
$ npx tsc --showConfig
{
"compilerOptions": {
"skipLibCheck": true,
"noUncheckedSideEffectImports": true
},
"files": [
"./globals.d.ts",
"./index.ts"
]
}
Run tsc --traceResolution and paste its output here
$ npx tsc --traceResolution
======== Resolving module './index.css' from '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.ts'. ========
Module resolution kind is not specified, using 'Node10'.
Loading module as file / folder, candidate module location '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.css', target file types: TypeScript, Declaration.
File name '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.css' has a '.css' extension - stripping it.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.d.css.ts' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.css.ts' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.css.tsx' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.css.d.ts' does not exist.
Directory '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.css' does not exist, skipping all lookups in it.
Loading module as file / folder, candidate module location '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.css', target file types: JavaScript.
File name '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.css' has a '.css' extension - stripping it.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.css.js' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.css.jsx' does not exist.
Directory '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.css' does not exist, skipping all lookups in it.
======== Module name './index.css' was not resolved. ========
======== Resolving module '@fontsource/roboto' from '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/index.ts'. ========
Module resolution kind is not specified, using 'Node10'.
Loading module '@fontsource/roboto' from 'node_modules' folder, target file types: TypeScript, Declaration.
Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.
Found 'package.json' at '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/package.json'.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto.ts' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto.tsx' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto.d.ts' does not exist.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' does not have a 'types' field.
'package.json' has 'main' field 'index.css' that references '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css'.
File name '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css' has a '.css' extension - stripping it.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.d.css.ts' does not exist.
Loading module as file / folder, candidate module location '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css', target file types: TypeScript, Declaration.
File name '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css' has a '.css' extension - stripping it.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.d.css.ts' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css.ts' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css.tsx' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css.d.ts' does not exist.
Directory '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css' does not exist, skipping all lookups in it.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.ts' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.tsx' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.d.ts' does not exist.
Directory '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'fontsource__roboto'
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'fontsource__roboto'
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'fontsource__roboto'
Directory '/home/jon/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'fontsource__roboto'
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'fontsource__roboto'
Directory '/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'fontsource__roboto'
Loading module '@fontsource/roboto' from 'node_modules' folder, target file types: JavaScript.
Searching all ancestor node_modules directories for fallback extensions: JavaScript.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/package.json' exists according to earlier cached lookups.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto.js' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto.jsx' does not exist.
'package.json' has 'main' field 'index.css' that references '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css'.
File name '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css' has a '.css' extension - stripping it.
Loading module as file / folder, candidate module location '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css', target file types: JavaScript.
File name '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css' has a '.css' extension - stripping it.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css.js' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css.jsx' does not exist.
Directory '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css' does not exist, skipping all lookups in it.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.js' does not exist.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.jsx' does not exist.
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
Resolution of non-relative name failed; trying with '--moduleResolution bundler' to see if project may need configuration update.
Loading module '@fontsource/roboto' from 'node_modules' folder, target file types: TypeScript, Declaration.
Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/package.json' exists according to earlier cached lookups.
Entering conditional exports.
Saw non-matching condition 'sass'.
Matched 'exports' condition 'default'.
Using 'exports' subpath '.' with target './index.css'.
File name '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.css' has a '.css' extension - stripping it.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@fontsource/roboto/index.d.css.ts' does not exist.
Failed to resolve under condition 'default'.
Exiting conditional exports.
Directory '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'fontsource__roboto'
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'fontsource__roboto'
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'fontsource__roboto'
Directory '/home/jon/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'fontsource__roboto'
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'fontsource__roboto'
Directory '/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'fontsource__roboto'
======== Module name '@fontsource/roboto' was not resolved. ========
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/lib/package.json' does not exist.
Found 'package.json' at '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/package.json'.
======== Resolving module '@typescript/lib-es5' from '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/__lib_node_modules_lookup_lib.es5.d.ts__.ts'. ========
Explicitly specified module resolution kind: 'Node10'.
Loading module '@typescript/lib-es5' from 'node_modules' folder, target file types: TypeScript, Declaration.
Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.
Directory '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-es5'
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-es5'
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-es5'
Directory '/home/jon/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-es5'
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-es5'
Directory '/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-es5'
Loading module '@typescript/lib-es5' from 'node_modules' folder, target file types: JavaScript.
Searching all ancestor node_modules directories for fallback extensions: JavaScript.
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name '@typescript/lib-es5' was not resolved. ========
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/package.json' exists according to earlier cached lookups.
======== Resolving module '@typescript/lib-decorators' from '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/__lib_node_modules_lookup_lib.decorators.d.ts__.ts'. ========
Explicitly specified module resolution kind: 'Node10'.
Loading module '@typescript/lib-decorators' from 'node_modules' folder, target file types: TypeScript, Declaration.
Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.
Directory '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-decorators'
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-decorators'
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-decorators'
Directory '/home/jon/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-decorators'
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-decorators'
Directory '/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-decorators'
Loading module '@typescript/lib-decorators' from 'node_modules' folder, target file types: JavaScript.
Searching all ancestor node_modules directories for fallback extensions: JavaScript.
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name '@typescript/lib-decorators' was not resolved. ========
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/package.json' exists according to earlier cached lookups.
======== Resolving module '@typescript/lib-decorators/legacy' from '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/__lib_node_modules_lookup_lib.decorators.legacy.d.ts__.ts'. ========
Explicitly specified module resolution kind: 'Node10'.
Loading module '@typescript/lib-decorators/legacy' from 'node_modules' folder, target file types: TypeScript, Declaration.
Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.
Directory '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-decorators/legacy'
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-decorators/legacy'
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-decorators/legacy'
Directory '/home/jon/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-decorators/legacy'
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-decorators/legacy'
Directory '/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-decorators/legacy'
Loading module '@typescript/lib-decorators/legacy' from 'node_modules' folder, target file types: JavaScript.
Searching all ancestor node_modules directories for fallback extensions: JavaScript.
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name '@typescript/lib-decorators/legacy' was not resolved. ========
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/package.json' exists according to earlier cached lookups.
======== Resolving module '@typescript/lib-dom' from '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/__lib_node_modules_lookup_lib.dom.d.ts__.ts'. ========
Explicitly specified module resolution kind: 'Node10'.
Loading module '@typescript/lib-dom' from 'node_modules' folder, target file types: TypeScript, Declaration.
Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.
Directory '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-dom'
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-dom'
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-dom'
Directory '/home/jon/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-dom'
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-dom'
Directory '/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-dom'
Loading module '@typescript/lib-dom' from 'node_modules' folder, target file types: JavaScript.
Searching all ancestor node_modules directories for fallback extensions: JavaScript.
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name '@typescript/lib-dom' was not resolved. ========
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/package.json' exists according to earlier cached lookups.
======== Resolving module '@typescript/lib-webworker/importscripts' from '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/__lib_node_modules_lookup_lib.webworker.importscripts.d.ts__.ts'. ========
Explicitly specified module resolution kind: 'Node10'.
Loading module '@typescript/lib-webworker/importscripts' from 'node_modules' folder, target file types: TypeScript, Declaration.
Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.
Directory '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-webworker/importscripts'
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-webworker/importscripts'
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-webworker/importscripts'
Directory '/home/jon/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-webworker/importscripts'
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-webworker/importscripts'
Directory '/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-webworker/importscripts'
Loading module '@typescript/lib-webworker/importscripts' from 'node_modules' folder, target file types: JavaScript.
Searching all ancestor node_modules directories for fallback extensions: JavaScript.
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name '@typescript/lib-webworker/importscripts' was not resolved. ========
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/package.json' exists according to earlier cached lookups.
======== Resolving module '@typescript/lib-scripthost' from '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/__lib_node_modules_lookup_lib.scripthost.d.ts__.ts'. ========
Explicitly specified module resolution kind: 'Node10'.
Loading module '@typescript/lib-scripthost' from 'node_modules' folder, target file types: TypeScript, Declaration.
Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.
Directory '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-scripthost'
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-scripthost'
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-scripthost'
Directory '/home/jon/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-scripthost'
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-scripthost'
Directory '/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'typescript__lib-scripthost'
Loading module '@typescript/lib-scripthost' from 'node_modules' folder, target file types: JavaScript.
Searching all ancestor node_modules directories for fallback extensions: JavaScript.
Directory '/home/jon/devel/jdufresne/node_modules' does not exist, skipping all lookups in it.
Directory '/home/jon/devel/node_modules' does not exist, skipping all lookups in it.
Directory '/home/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name '@typescript/lib-scripthost' was not resolved. ========
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/home/jon/devel/jdufresne/typescript-nouncheckedsideeffectimports/node_modules/typescript/package.json' exists according to earlier cached lookups.
index.ts:2:8 - error TS2307: Cannot find module '@fontsource/roboto' or its corresponding type declarations.
2 import "@fontsource/roboto";
~~~~~~~~~~~~~~~~~~~~
Found 1 error in index.ts:2
Paste the package.json of the importing module, if it exists
{
"name": "typescript-nouncheckedsideeffectimports",
"dependencies": {
"@fontsource/roboto": "^5.2.8",
"typescript": "^5.9.3"
}
}Paste the package.json of the target module, if it exists
{
"name": "@fontsource/roboto",
"version": "5.2.8",
"description": "Self-host the Roboto font in a neatly bundled NPM package.",
"main": "index.css",
"publishConfig": {"access": "public"},
"keywords": [
"fontsource",
"font",
"font family",
"google fonts",
"roboto",
"Roboto",
"css",
"sass",
"front-end",
"web",
"typeface",
"variable"
],
"exports": {
".": {"sass": "./index.css", "default": "./index.css"},
"./LICENSE": "./LICENSE",
"./*": {"sass": "./*.css", "default": "./*.css"},
"./*.css": {"sass": "./*.css", "default": "./*.css"},
"./files/*": {"sass": "./files/*", "default": "./files/*"},
"./files/*.woff": {"sass": "./files/*.woff", "default": "./files/*.woff"},
"./files/*.woff2": {
"sass": "./files/*.woff2",
"default": "./files/*.woff2"
},
"./package.json": "./package.json",
"./metadata.json": "./metadata.json",
"./unicode.json": "./unicode.json",
"./scss": {"sass": "./scss/metadata.scss"}
},
"author": "Google Inc.",
"license": "OFL-1.1",
"homepage": "https://fontsource.org/fonts/roboto",
"funding": "https://github.com/sponsors/ayuhito",
"repository": {
"type": "git",
"url": "git+https://github.com/fontsource/font-files.git",
"directory": "fonts/google/roboto"
},
"publishHash": "796e33ab906c9be2"
}Any other comments can go here
My goal is to enable the recommended option: noUncheckedSideEffectImports. The docs state to add "an ambient module declaration with a wildcard specifier." I've done this; the example repository demonstrate this by importing a local "index.css" file. However, it isn't being applied to the CSS-only module in node_modules so it creates the error pasted above.
This is a weird case. The only reason this kind of import worked at all is because these imports were previously entirely unchecked; nothing else actually handles this.
Module specifiers like these are resolved by the module resolver during Program load, before the checker does anything. In this case, the package doesn't point to any loadable file (JS/TS/JSON), so the resolution fails and nothing is recorded.
Then later, the checker comes along and queries the info built up by the module resolver during load. Resolution failed, so nothing was recorded, so the checker reports a module resolution failure.
The ambient declaration doesn't help here, because the actual import specifier written in the code (@fontsource/roboto) does not match the glob *.css.
I don't think the module resolver saves any info at all about resolutions that don't point to JS/TS files, which would be required here to "remember" that this specifier technically resolved to a CSS file.
I am not sure what to do about this. Maybe @andrewbranch has an idea.
(A workaround at the moment given the above is to write @fontsource/roboto/index.css, though that seems unsatisfying. Or for them to publish .d.css.ts files with export {}.)
We decided to experiment with adding a field on the resolution that says “we were requested to look up a file with an extension that we won’t actually look up” so we can silence these errors on those resolutions.
I looked into this, and it’s a little tricky to get it right. I tried setting a state flag whenever we're asked to try a file with an extension we would normally skip, and unsetting the flag on other file lookups, but in the example above, after setting the flag, we continue on to try index.css.ts, index.css.d.ts and so on because of CJS lookup rules. So we could leave the flag set permanently, but that’s not quite right, because we wouldn't want to leave it set if, e.g., there was an index.css/ directory but we failed to resolve in there, or if we found a node_modules/@types/fontsource__roboto but we failed to resolve in there. Getting the boundaries right for what counts as trying an unsupported extension is not as simple as it sounds.
Thanks for looking into this. I’m pretty sure Fontsource is the not the only example abusing this, but since I am planning on a major release down the line, I could update the default documentation to something that is more blessed by the TypeScript team? I can also add the workaround if that is what TypeScript would bless.
Also another fleeting thought, but I wonder if it would be nice to give the ability for Intellisense and TypeDocs for CSS (or alternative extensions) imports via declaration files? Which might be a way to opt in as a “checked side effect”? Or maybe I’m missing something here.
I would say the suggestion in fontsource/fontsource#1086 is the correct fix here, or at least a correct fix.
Alternatively, one can take the view that if you're writing import "@fontsource/roboto"; and have noUncheckedSideEffectImports on, an error is the correct behavior, since this import truly does fail at runtime (in the absence of a bundling step):
node:internal/modules/esm/get_format:219
throw new ERR_UNKNOWN_FILE_EXTENSION(ext, filepath);
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".css" for node_modules\@fontsource\roboto\index.css
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:219:9)
Since the only legal way to be in this state is in the presence of a bundler, you could reasonably say that this is properly a bundler error since only the bundler can tell you what a valid file to import is, and people in this configuration should turn off noUncheckedSideEffectImports and instead have the bundler be the source of truth as to which imports are valid and which aren't.
Aside: the behavior requested by this bug conflates two things: module specifiers, and file names. When resolving @fontsource/roboto, we have a module specifier, which is a thing that goes through export maps, etc..
This issue has been marked as "Question" and has seen no recent activity. It has been automatically closed for house-keeping purposes.