简体   繁体   English

Node.js v18.3.0“导出”和“导入”VS 代码不起作用

[英]Node.js v18.3.0 "Export" and "Import" VS Code not working

Attempting to export a class and use as an extention for another class.. I've even tried module.export at the bottom and export class at the top.尝试导出一个类并用作另一个类的扩展。我什至尝试了底部的 module.export 和顶部的导出类。 What am I doing wrong?我究竟做错了什么? Also tried changing to .mjs还尝试更改为 .mjs

File: -animal.js -dog.js -test.js文件:-animal.js -dog.js -test.js

animal.js:动物.js:

class Animal {
....
    
}

export {Animal}

dog.js:狗.js:

import {Animal} from 'animal.js';

class Dog extends Animal{
...
}

There's not much setup details to go on, but one thing I noticed is your import path is absolute... which is generally reserved for node modules没有太多设置细节要继续,但我注意到的一件事是你的导入路径是绝对的......这通常是为节点模块保留的

import {Animal} from 'animal.js';

I'd expect it to be relative, more like我希望它是相对的,更像是

import {Animal} from '../animal';
or
import {Animal} from './animal';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM