我的文件都是
.mjs
我有
fizz_buzz.mjs
和
test/fizz_buzz.spec.mjs
import { fizzBuzz } from '../fizz_buzz'
npm test
> mocha test/**/*.spec.mjs
/home/durrantm/Dropbox/90_2019/work/code/js/mocha_chai_bdd_tdd_exercises/node_modules/yargs/yargs.js:1163
else throw err
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/durrantm/Dropbox/90_2019/work/code/js/mocha_chai_bdd_tdd_exercises/test/fizz_buzz.spec
.mjs
at Object.Module._extensions..mjs (internal/modules/cjs/loader.js:1025:9)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Module.require (internal/modules/cjs/loader.js:848:19)
嘶嘶作响.mjs
目前只有:
$ cat fizz_buzz.mjs
export function fizzBuzz() {
return true
}
仅供参考
package .json
"scripts": {
"test": "mocha test/**/*.spec.mjs"
},
万一这就是问题所在?
$ mocha test/**/*.spec.mjs --experimental-modules
但同样的错误