admin管理员组

文章数量:1287488

I am looking at this specific line of code to understand what it is or to find some documentation about it.

.js

const Lucid = use('Lucid')

I am trying to write a test in adonisjs using mocha and it gives me the following error "ReferenceError: use is not defined"

I am looking at this specific line of code to understand what it is or to find some documentation about it.

https://github./adonisjs/adonis-rally/blob/c7378d2c3984bffba1049f50e771318ea447107c/app/Model/Channel.js

const Lucid = use('Lucid')

I am trying to write a test in adonisjs using mocha and it gives me the following error "ReferenceError: use is not defined"

Share Improve this question asked Dec 21, 2016 at 17:21 shed_fortestshed_fortest 611 gold badge1 silver badge3 bronze badges 4
  • This is not a standard part of Javascript or node.js. In that particular code, it looks like something similar to require() that would be in some library which you do not appear to have available. – jfriend00 Commented Dec 21, 2016 at 17:23
  • 6 There is no use keyword. That is a function call - some library defines it. You don't seem to have that library loaded. – VLAZ Commented Dec 21, 2016 at 17:23
  • Look in the package.json to see the installed packages – Andrew Li Commented Dec 21, 2016 at 17:24
  • I copied the package json from that project i linked to my project and I still cannot run a test. My model looks exactly the same as the model linked. – shed_fortest Commented Dec 21, 2016 at 17:36
Add a ment  | 

2 Answers 2

Reset to default 7

The use() function is provided by adonis.js.

use(namespace/alias)

Fetch a binding using it’s namespace or alias.

The adonis-lucid package has an example of how to create a model that looks identical to the code that you've linked in your question. Creating a model docs

To plete the answer. use() function is provided by the IoC Container of AdonisJs (adonis-fold).

This function will try to resolve a binding or a namespace defined in your Adonis configuration file and will then fallback to the default require() function to import a package if it didn't find anything.

本文标签: nodejswhat is the 39use39 keyword in javascriptStack Overflow