简体   繁体   English

我正在为 node.js 使用 ES6 语法,并且我已导出模块但尝试导入时出现错误无法找到模块

[英]I am using ES6 syntax for node.js and I have exported module but trying to import gives error Cannot find module

index.js索引.js

import { Time} from './service/passport';

passport.js护照.js

const Time = async () => {
   console.log('done');
}

export { Time }

I am using EcmaScript or es6 in node.js but when I try to export above module it is giving me error Can't find module but I have exported module don't know why still getting error any help will be appreciated我在 node.js 中使用 EcmaScript 或 es6,但是当我尝试导出上面的模块时,它给了我错误无法找到模块但我已经导出模块不知道为什么仍然出现错误任何帮助将不胜感激

Need to add file extension only instead of只需要添加文件扩展名而不是

import { Time} from './service/passport';

use采用

import { Time} from './service/passport.js';

it will be done将会完成

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

相关问题 我正在尝试运行 node.js,如何解决“找不到模块”错误? - I am trying to run node.js, how do I resolve "Cannot find module" error? Node.js 无法导入 ES6 模块 - Node.js unable to import ES6 module 为什么我无法使用Typescript / node.js导入模块? - Why am I unable to import a module with Typescript / node.js? 我无法在 node.JS 中使用我的 ES6 语法 - I am not being able to use my ES6 syntax in node.JS 为什么 Jest 一直给我错误“SyntaxError: Cannot use import statement outside a module'”? 我正在使用 Babel 转译 ES6 以供 Jest 测试 - Why does Jest keep giving me error "SyntaxError: Cannot use import statement outside a module' "? I am using Babel to transpile ES6 for Jest to test 如何模拟使用在节点模块中导出的导入(ES6 打字稿)进行单元测试的外部注入库 - How do I mock externally injected libraries that use import (ES6 typescript) exported in a node module for unit testing 尝试 ES6 样式导入会给出“无法在模块外使用导入语句” - Trying ES6 style import gives 'Cannot use import statement outside a module' 找不到模块./dist/es5 node.js - cannot find module ./dist/es5 node.js 使用 Node.js 出现“错误:找不到模块” - Getting a "Error: Cannot find module" using Node.js 我可以动态导入 ES6 模块吗? - Can I dynamically import an ES6 module?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM