语句"/>
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语句
发布评论