Skip to content

Conversation

Borewit
Copy link
Owner

@Borewit Borewit commented Mar 10, 2025

Add stub to fool TypeScript compiler, loading the wrong entry points for the typings.

For calling the runtime problems, it throws an error.

Change suggested by @net: #2370 (comment)

Add stub to fool TypeScript compiler, loading the wrong entry points for the typings.

For calling the runtime problems, it throws an error.
@Borewit Borewit added the improvement Improvement of existing functionality label Mar 10, 2025
@Borewit Borewit self-assigned this Mar 10, 2025
@coveralls
Copy link

Coverage Status

coverage: 96.993% (-0.01%) from 97.006%
when pulling 17c1cd4 on stub-workaround-suggested-by-net
into 29ecceb on master.

Comment on lines +128 to +134
/**
* Implementation only available when loaded as Node.js
* This method will throw an Error, always.
*/
export async function parseFile(filePath: string, options: IOptions = {}): Promise<IAudioMetadata> {
throw new Error('To load Web API File objects use parseBlob instead. For loading files, you need to import with the "node" condition is set.');
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like

Suggested change
/**
* Implementation only available when loaded as Node.js
* This method will throw an Error, always.
*/
export async function parseFile(filePath: string, options: IOptions = {}): Promise<IAudioMetadata> {
throw new Error('To load Web API File objects use parseBlob instead. For loading files, you need to import with the "node" condition is set.');
}
/**
* Parse audio from Node file
*
* Only available when running in a Node.js environment.
*
* @param filePath - Media file to read meta-data from
* @param options - Parsing options
* @returns Metadata
*/
export async function parseFile(filePath: string, options: IOptions = {}): Promise<IAudioMetadata> {
throw new Error(`music-metadata's parseFile is not available in this runtime.
If you are running in a browser, use parseBlob instead.
If you are running in a Node.js environment, you may need to set
"customConditions": ["node"]
in your tsconfig.json.
(See https://github.com/Borewit/music-metadata/issues/2370.)`);
}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "customConditions": ["node"] is TypeScript specific, and with TypeScript the user will not get this error.

@Borewit Borewit merged commit 8c540bd into master Mar 10, 2025
27 checks passed
@Borewit Borewit deleted the stub-workaround-suggested-by-net branch March 10, 2025 19:03
@Borewit
Copy link
Owner Author

Borewit commented Mar 10, 2025

Part of v11.0.2

@Borewit Borewit linked an issue Mar 10, 2025 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot use parseFile if the TypeScript compiler moduleResolution is set to bundler
3 participants