// @flow
const Hapi = require(`hapi`)
gives this:
server.js:9
9: const Hapi = require(`hapi`)
^^^^^^^^^^^^^^^ The parameter passed to require() must be a literal string.
backticks*
thanks :-)
Sorry I didn't see this before, but if you wish to suppress this particular kind of error you can use the following config flag:
module.ignore_non_literal_requires=true
Note that if you do this, Flow won't be able to extract a type for the require(), though (which is why it errors by default).
I think we should just support template literals as long as there are no expressions
@jeffmo it would be nice to parse contents of template and figure out that it's static though
I did something similar in https://github.com/facebook/flow/commit/127f0dd28af0e73de92ec4d6336904a1411f4ec7
The changelog says this was fixed in v0.38.0 but I'm using v0.41.0 and still seeing this error:
65: const originalCode = routeParams.component ? require(`raw-loader!./../examples/${routeParams.component}`) : null;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The parameter passed to require() must be a literal string.
Any idea what could be going wrong?
@EvNaverniouk You are using ${routeParams.component} to inject a non-constant string into your module name. This is not allowed.
This is because flow runs staticly. It can't verify which module it will resolve to dynamically.
How could I mitigate this? Is there a way to tell Flow not to check this line? Or to accept a non-constant string for all require statements?
@EvNaverniouk Is this not precisely what module.ignore_non_literal_requires=true does? (mentioned above)
Most helpful comment
Sorry I didn't see this before, but if you wish to suppress this particular kind of error you can use the following config flag:
module.ignore_non_literal_requires=trueNote that if you do this, Flow won't be able to extract a type for the
require(), though (which is why it errors by default).