admin管理员组文章数量:1427348
This line of code is giving me problems,
import * as posenet from '@tensorflow-models/posenet'
And I get this error 'Uncaught SyntaxError: Unexpected token *',
I am using the latest version of chrome and have npm package '@tensorflow-models/posenet' installed.I am using npm package 'http-server' to localhost my page.
This line of code is giving me problems,
import * as posenet from '@tensorflow-models/posenet'
And I get this error 'Uncaught SyntaxError: Unexpected token *',
I am using the latest version of chrome and have npm package '@tensorflow-models/posenet' installed.I am using npm package 'http-server' to localhost my page.
Share Improve this question asked Sep 15, 2018 at 18:28 IexistIexist 531 silver badge7 bronze badges 2- you might need babel to transpile ? – ashish singh Commented Sep 15, 2018 at 18:30
- if this js file is being piled by the browser you need type="module" in script tag – Chris Li Commented Sep 15, 2018 at 18:36
2 Answers
Reset to default 3You can't import npm packages directly like that as the browser has no idea where a package on your server is stored.
In the browser you import javascript files directly using it's path, ie from 'some/file.js'
. Also your code has to be in a module type script element for it to use the import/export syntax. For instance
<script type="module">
import * as someName from 'some/file.js';
</script>
When using TS in node, specify a correct module
in tsconfig.json
.
E.g,
{
"pilerOptions": {
"module": "monjs",
...
}
}
本文标签: javascriptUnexpected token (*)Stack Overflow
版权声明:本文标题:javascript - Unexpected token (*) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745464571a2659475.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论