NodeJs项目语法错误:无法在模块外部使用import语句

编程入门 行业动态 更新时间:2024-10-10 09:26:15

NodeJs项目语法错误:无法在模块外部使用import<a href=https://www.elefans.com/category/jswz/34/1770772.html style=语句"/>

NodeJs项目语法错误:无法在模块外部使用import语句

我在./constant/assets文件夹中有一个文件。当我尝试运行程序node index.ts时我收到以下错误;SyntaxError:无法在模块外部使用import语句这是我要导入的内容

import {  USERNAME_SELECTOR, PASSWORD_SELECTOR, BUTTON_SELECTOR } from './constant/assets';

我的资产文件

export const  USERNAME_SELECTOR = '#UserName';
export const PASSWORD_SELECTOR = '#User_Password';
export const BUTTON_SELECTOR = '#LoginUserLoginButton';

我一直在网上阅读,人们谈论使用<script type="module" src="./index.js"></script>,但我不认为我正在使用该格式。我有package.json

回答如下:

基本上是为任何需要答案的人提供的,您需要进行模块导出。您可以导出函数或变量

// a beginner film course
let film101 = {
    professor: 'Mr Caruthers',
    numberOfStudents: 20,
    level: 'easy'
}

// an expert film course
let film102 = {
    professor: 'Mrs Duguid',
    numberOfStudents: 8,
    level: 'challenging' 
}

// export the courses so other modules can use them
exports.film101 = film101;
exports.film102 = film102;

更多推荐

NodeJs项目语法错误:无法在模块外部使用import语句

本文发布于:2024-05-07 09:33:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1755631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   模块   语法错误   项目   NodeJs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!