es6 modules - how to use ES6 file in CommonJS using Adonisjs - Stack Overflow

I'm a C++ developer. I barely do any web related stuff. So please bear with me.I'm using ado

I'm a C++ developer. I barely do any web related stuff. So please bear with me.

I'm using adonisjs. Everything is fine. I have a javascript file which works just fine. It does some numerical calculations.

I want to add unit tests to it. I've read a lot of questions like this: How to use ES6 modules in CommonJS? but have not been able to figure out what I need to do to use the file in my unit tests.

My last attempt was to use dynamic import, but I still get an error. This is the minimal code I have that reproduces the issue:

import { test } from '@japa/runner'

Test('seisUtils lib test', async ({ assert }) => {

  import ('../../resources/js/libs/seisUtils.mjs').then(seisUtils => {
    let signal1 = utils.ricker(100, 10, 0);
    assert.isTrue(true);
  });

})

result:

require() of ES Module

<directory>/resources/js/libs/seisUtils.mjs not supported.
Instead change the require of <directory>/resources/js/libs/seisUtils.mjs to a dynamic import() which is available in all CommonJS modules.
  
   at anonymous tests/unit/first_breaks_lib_test.spec.ts:28

I tried using webpack, but then I messed up the configuration of adonis and gave up. Maybe that's the correct way to do it?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745659741a4638760.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信