SyntaxError: Unexpected identifier - Received when trying to seed data with AdonisJS

时间:2018-07-25 04:32:34

标签: adonis.js

I have changed both files as far as commas and semicolons, both of which have been driving eslint crazy. Nothing seems to appease it within factory.js especially, but the odd error messages that I am getting below make me think this may be something else. Anyone have any experience with this?

UserSeeder.js

const Factory = use('Factory');
const Database = use('Database');

class UserSeeder {
  async run () {

    const user = await Factory
    .model('App/Models/User')
    .create()

    const users = await Database.table('users');
    console.log(users);
  }
}   

module.exports = UserSeeder;

factory.js

const Factory = use('Factory');
const Hash = use('Hash');


Factory.blueprint('App/Models/User', () => {
  return {
    username: 'test',
    email: 'test@test.com',
    password: await Hash.make('test'),
  } 
});

And the lovely and informative error message:

SyntaxError: Unexpected identifier

1 _preLoadFiles.forEach
  D:\Source\VuePractice\intro-to-vuetify-with- 
  adonis\server\node_modules\@adonisjs\ignitor\src\Ignitor\index.js:375

2 Ignitor._loadPreLoadFiles
  D:\Source\VuePractice\intro-to-vuetify-with- 
  adonis\server\node_modules\@adonisjs\ignitor\src\Ignitor\index.js:367

3 Ignitor.fire
  D:\Source\VuePractice\intro-to-vuetify-with- 
  adonis\server\node_modules\@adonisjs\ignitor\src\Ignitor\index.js:760

2 个答案:

答案 0 :(得分:1)

您的代码中存在的问题是您在await的工厂中使用关键字App/Models/User,而回调不是async

它必须是:

const Hash = use('Hash')
const Factory = use('Factory')

Factory.blueprint('App/Models/User', async () => {
  return {
    username: 'test',
    email: 'test@test.com',
    password: await Hash.make('test'),
  } 
})

答案 1 :(得分:0)

就我而言,这只是我的 start/routes.js 文件中的一个错字。

Error on line 24, I accidentally added a 'v' to the end of the line

它给了我下一个错误。

我解决了删除额外字符的问题。我希望它可以帮助任何有同样错误的人。