我正在编写一个简单的程序,该程序使用充满字典单词的对象。我想从另一个文件中导入该对象,因为它很大。尝试导入它时,我收到一个错误,看起来像Node.js不知道它是什么。
我已经尝试过重新安装最新版本的Node.js。
这是重要的代码:
import {dict} from './words_dictionary'
Run Code Online (Sandbox Code Playgroud)
这就是全部:
import {dict} from './words_dictionary'
function exists(obj,str) {
if(obj[str]) {
return true
} else {
return false
}
}
console.log(exists(dict, 'hello'))
Run Code Online (Sandbox Code Playgroud)
这是字典代码的要点:
export let dict = {a: 1, aa: 1, aaa: 1, aah: 1, aahed: 1, aahing: 1, aahs:
1, aal: 1, aalii: 1, aaliis: 1, aals: 1, aam: 1, aani: 1, aardvark: 1,
aardvarks: 1,...~3000 more}
Run Code Online (Sandbox Code Playgroud)
我原以为是,但是我得到了这个错误:
SyntaxError: Unexpected token {
at new Script (vm.js:84:7)
at createScript (vm.js:264:10)
at Object.runInThisContext (vm.js:312:10)
at …Run Code Online (Sandbox Code Playgroud)