0

Hi I am building next js app where I have folder structure like pages [state_name] [city_name].js

I have added one method inside [city_name].js file,how can I import that method as I tried

import {setState} from '../[state_name]/[city_name]' 

but it is giving error saying Module not found: Can't resolve '../[state_name]/[city_name]' Can anyone tell me how can I import this method

Puja Garg
  • 251
  • 3
  • 11
  • Does this answer your question? [ES6 variable import name in node.js?](https://stackoverflow.com/questions/29168433/es6-variable-import-name-in-node-js) – Dai Sep 23 '20 at 05:57
  • You can't. The ECMAScript `import` statement requires the use of string-literals, therefore module imports cannot be determined at runtime. But if this is code that will run inside NodeJS (rather than in a browser) you may be able to use `require()`. – Dai Sep 23 '20 at 05:57
  • Instead of importing from "../[state_name]/[city_name]" you can add a util file and import it from there. – Anusha Bhat Sep 23 '20 at 06:01
  • Try using the approach mentioned here: https://stackoverflow.com/a/54257036/6333527 – waleed ali Sep 23 '20 at 06:12

0 Answers0