如何将错误“意外令牌”修复到Sapper项目中

时间:2019-04-09 11:07:42

标签: javascript

我使用nvm将节点js从10.14.1切换到10.15.3,启动了项目npm run dev,并得到了一个错误。

C:\user\project>npm run dev
> sapper dev
 ✗ server
 Unexpected token (1:63) 
 ✗ client Unexpected token (1:63)

Did:删除并重新安装软件包

> rm -rf `node_modules`
> npm i

1 个答案:

答案 0 :(得分:0)

这是组件的语法错误。 如果在组件<button on:click></button>的开头添加=""到结尾on:click并启动项目npm run dev,则会出错

C:\Users\admin\project> npm run dev         

> web_channel-mnp_om@0.0.1 dev C:\Users\admin\project
> sapper dev

✗ server
Unexpected token (1:63)
✗ client
Unexpected token (1:63)

如果在项目npm run dev的开头运行项目<button on:click></button>之后,将=""添加到结尾on:click,则出错

(node:6220) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'fileName' of undefined
    at _loop_1 (C:\Users\admin\my-project\node_modules\sapper\dist\core.js:354:111)
    at new RollupResult (C:\Users\admin\my-project\node_modules\sapper\dist\core.js:358:17)
    at class_1.<anonymous> (C:\Users\admin\my-project\node_modules\sapper\dist\core.js:528:46)
    at class_1.emit (events.js:189:13)
    at Watcher.emit (C:\Users\admin\my-project\node_modules\rollup\dist\rollup.js:38118:22)
    at C:\Users\admin\my-project\node_modules\rollup\dist\rollup.js:38163:19
(node:6220) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:6220) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
✗ client
Unexpected token (1:63)
(node:6220) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'imports' of undefined
    at C:\Users\admin\my-project\node_modules\sapper\dist\core.js:267:15
    at Set.forEach (<anonymous>)
    at extract_css (C:\Users\admin\my-project\node_modules\sapper\dist\core.js:266:30)
    at RollupResult.to_json (C:\Users\admin\my-project\node_modules\sapper\dist\core.js:394:18)
    at handle_result (C:\Users\admin\my-project\node_modules\sapper\dist\dev.js:262:55)
    at C:\Users\admin\my-project\node_modules\sapper\dist\dev.js:346:17
    at class_1.<anonymous> (C:\Users\admin\my-project\node_modules\sapper\dist\core.js:528:37)
    at class_1.emit (events.js:189:13)
    at Watcher.emit (C:\Users\admin\my-project\node_modules\rollup\dist\rollup.js:38118:22)
    at C:\Users\admin\my-project\node_modules\rollup\dist\rollup.js:38163:19
(node:6220) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

结论:需要删除=""