Javascript 从'导入{expect};柴;;SyntaxError:无法在模块外部使用导入语句

Javascript 从'导入{expect};柴;;SyntaxError:无法在模块外部使用导入语句,javascript,chai,Javascript,Chai,在测试其中一个功能时,我遇到了这种错误。有什么问题 import { expect } from 'chai'; import { PathFinding } from './path-finding.js'; describe('aStar', () => { const o = 0; // intermediate points when going forwards (the trace) const u = 0; // turning points const s =

在测试其中一个功能时,我遇到了这种错误。有什么问题

import { expect } from 'chai';
import { PathFinding } from './path-finding.js';

describe('aStar', () => {
  const o = 0; // intermediate points when going forwards (the trace)
  const u = 0; // turning points
  const s = 0;
  const f = 0;

  it('should find a valid path', () => {
    const graph = [
      [0, u, o, o, f],
      [u, 1, 1, 1, 1],
      [0, u, o, u, 0],
      [1, 1, 1, 1, u],
      [s, o, o, u, 0],
    ];
    const start = { x: 0, y: 4 };
    const finish = { x: 4, y: 0 };
    const path = PathFinding.aStar({ graph, start, finish });
    expect(path).to.eql([
      { x: 3, y: 4 },
      { x: 4, y: 3 },
      { x: 3, y: 2 },
      { x: 1, y: 2 },
      { x: 0, y: 1 },
      { x: 1, y: 0 },
      finish,
    ]);
  });

...
/Users/user/websprojects/hsu/src/path finding/path finding.spec.js:1 从“chai”导入{expect}; ^^^^^^

SyntaxError:无法在模块外部使用导入语句 在wrapSafe(节点:内部/模块/cjs/加载器:1018:16) at模块编译(节点:内部/modules/cjs/loader:1066:27) 在Object.Module._extensions..js(节点:internal/modules/cjs/loader:1131:10) at Module.load(节点:内部/模块/cjs/加载器:967:32) at功能模块加载(节点:内部/模块/cjs/加载程序:807:14) at Module.require(节点:内部/模块/cjs/加载器:991:19) 需要时(节点:内部/模块/cjs/helpers:92:18) 在Object.exports.requireOrImport(/Users/antongorshkov/WebstormProjects/hsu/node_modules/mocha/lib/esm utils.js:20:12) 在Object.exports.loadfilesaync(/Users/antongorshkov/WebstormProjects/hsu/node_modules/mocha/lib/esm utils.js:33:34) 在Mocha.loadfileasync(/Users/antongorshkov/WebstormProjects/hsu/node_modules/Mocha/lib/Mocha.js:431:19) 在singleRun(/Users/antongorshkov/WebstormProjects/hsu/node_modules/mocha/lib/cli/run helpers.js:125:15) 在exports.runMocha(/Users/antongorshkov/WebstormProjects/hsu/node_modules/mocha/lib/cli/run helpers.js:190:10) 在Object.exports.handler(/Users/antongorshkov/WebstormProjects/hsu/node_modules/mocha/lib/cli/run.js:362:11)
在/Users/antongorshkov/WebstormProjects/hsu/node_modules/yargs/lib/command.js:241:49

node.js遵循CommonJS模块系统<代码>要求

const{expect}=require('chai');
const{PathFinding}=require('./path finding.js');

您是如何运行测试的?你用的是运输机吗?