nodejs使用import报错:导出模块://D:/workspace/www/hello-world/src/data/articles.jsconstarticles=[{"title":"title1","content":"content1"},{"title":"title2","content":"content2"},{"title":"title3","content":"content3"}]exportdefaultarticles;导入模块://D:/workspace/www/nodejs_scripts/test.jsimportarticlesfrom'D:/workspace/www/hello-world/src/data/articles';console.log(articles);在命令行中运行test.js,报错:D:\workspace\www\nodejs_scriptsλnode-vv12.11.1D:\workspace\www\nodejs_scriptsλnodetest.jsD:\workspace\www\nodejs_scripts\test.js:3importarticlesfrom'D:/workspace/www/hello-world/src/data/articles';^^^^^^SyntaxError:CannotuseimportstatementoutsideamoduleatModule._compile(internal/modules/cjs/loader.js:881:18)atObject.Module._extensions..js(internal/modules/cjs/loader.js:962:10)atModule.load(internal/modules/cjs/loader.js:798:32)atFunction.Module._load(internal/modules/cjs/loader.js:711:12)atFunction.Module.runMain(internal/modules/cjs/loader.js:1014:10)atinternal/main/run_main_module.js:17:11应该怎么做呢?
慕莱坞森
相关分类