I am trying to setup some tests with ts-node and tape for my React components, but I am encountering some imports like import 'style.css'; which are meant to be processed by Webpack and ignored by Typescript. The problem is that ts-node attempts to parse it as Typescript and then (obviously) fails.
Is there something we can do here so solve this?
This is not ts-node, this is just how node works. There isn't any way to do what you want in node except to use conditional requires.
Okay, thanks for the tip. I suppose I should use something like this then?
@JabX That looks like it could work. By default, any require will be execute by node and that's exactly (educated guess) what's happening here. You'd be running into a runtime error, not because of TypeScript, but because node is trying to evaluate your CSS and JavaScript.
I apologize for resurrecting this thread more than two years after its closing, but CSS file imports remain the primary reason why I have to resort to using Webpack on the server-side instead of being able to use ts-node.
My understanding is that a statement like import 'style.css'; will be converted by TypeScript to require('style.css');. I am hoping for a way in my tsconfig.json to specify that import 'style.css'; should be converted into a blank empty line instead.
@onlywei That's out of scope for this module though, I'm sure there's projects well defined for this sort of things (it's really just doing require.extensions['.css'] = () => undefined).
Most helpful comment
@onlywei That's out of scope for this module though, I'm sure there's projects well defined for this sort of things (it's really just doing
require.extensions['.css'] = () => undefined).