MCPcopy Create free account
hub / github.com/nodejs/node / emitLegacyIndexDeprecation

Function emitLegacyIndexDeprecation

lib/internal/modules/esm/resolve.js:124–151  ·  view source on GitHub ↗

* Emits a deprecation warning if the given URL is a module and * the package.json file does not define a "main" or "exports" field. * @param {URL} url - The URL of the module being resolved. * @param {string} path - The path of the module being resolved. * @param {string} pkgPath - The path of t

(url, path, pkgPath, base, main)

Source from the content-addressed store, hash-verified

122 * @param {string} [main] - The "main" field from the package.json file.
123 */
124function emitLegacyIndexDeprecation(url, path, pkgPath, base, main) {
125 if (process.noDeprecation) {
126 return;
127 }
128 const format = defaultGetFormatWithoutErrors(url);
129 if (format !== 'module') { return; }
130 const basePath = fileURLToPath(base);
131 if (!main) {
132 process.emitWarning(
133 `No "main" or "exports" field defined in the package.json for ${pkgPath
134 } resolving the main entry point "${
135 StringPrototypeSlice(path, pkgPath.length)}", imported from ${basePath
136 }.\nDefault "index" lookups for the main are deprecated for ES modules.`,
137 'DeprecationWarning',
138 'DEP0151',
139 );
140 } else if (resolve(pkgPath, main) !== path) {
141 process.emitWarning(
142 `Package ${pkgPath} has a "main" field set to "${main}", ` +
143 `excluding the full filename and extension to the resolved file at "${
144 StringPrototypeSlice(path, pkgPath.length)}", imported from ${
145 basePath}.\n Automatic extension resolution of the "main" field is ` +
146 'deprecated for ES modules.',
147 'DeprecationWarning',
148 'DEP0151',
149 );
150 }
151}
152
153const realpathCache = new SafeMap();
154

Callers 1

legacyMainResolveFunction · 0.85

Calls 3

fileURLToPathFunction · 0.85
resolveFunction · 0.50

Tested by

no test coverage detected