dsherret / ts-nameof

nameof in TypeScript
MIT License
492 stars 23 forks source link

Can't resolve 'fs' #86

Closed john-larson closed 4 years ago

john-larson commented 4 years ago

I am trying to use this library in a single page web application on the browser using Webpack. I installed the library via NPM. And I get the following error:

Can't resolve 'fs'

I do not know much about this module but a quick Google search seems to imply that it is a Node specific module. Is this library Node specific?

dsherret commented 4 years ago

How are you using the library and which installation instructions did you follow? Make sure it’s a dev dependency... it’s a compile time transformation so it shouldn’t be used in any code at runtime.

dsherret commented 4 years ago

See https://github.com/dsherret/ts-nameof/blob/master/packages/ts-nameof/setup/webpack.md

john-larson commented 4 years ago

I thought this was a run-time library. So, after making this configuration in Webpack.config, how should I use it in TypeScript without importing? Should I declare it as any in some part of my code?

dsherret commented 4 years ago

Install @types/ts-nameof as well:

npm install ts-nameof @types/ts-nameof --save-dev

(Step 2: https://github.com/dsherret/ts-nameof/tree/master/packages/ts-nameof#setup)

Then you'll just be able to use nameof(something)

dsherret commented 4 years ago

I'll have to add something more clear to the main readme.md file.

john-larson commented 4 years ago

Thanks for the prompt help :thumbsup: