How to use import instead of ioc.use when use Env library?


I want to use es6 import when using adonis libraries.

// this
const Route = use('Route')
// can be subsituted with
import Route from '@adonisjs/framework/src/Route/Manager'

// but this
const Env = use('Env')
// can not be subsituted with
import Env from '@adonisjs/framework/src/Env'

What did I do wrong?


You cannot !

Please, read :


In short

The use method resolves the dependency from IoC container

The import keyword and require resolves it from file system.

Though the dependency inside IoC Container will be file-system, but the IoC container, but they both are not same.

Understanding IoC container will take some of your time, so If interested, please read the docs