D:\iota\code\web\iota-api-server-scaffold\node_modules\iota-user\index.js:4
import * as auth from './src/auth';
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
at Module._extensions..js (module.js:550:10)
at Object.require.extensions.(anonymous function) [as .js] (C:\Users\35824\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-register\lib\node.js:166:7)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (config.js:10:1)
npm set registry 本地仓库
npm adduser --registry 本地仓库
npm publish
编译用的 babel,
我怀疑是在引入后不识别模块里的node_modules了,
那么是我发布的方式不对,还是需要什么命令转换?
Does "babel for compilation" refer to the class library project
iota-user
, or the project currently referencing the class libraryiota-api-server-scaffold
?of the
iota-user
package.json
main
project refer to?babel
After compilation, or the source file before the compiler?It is recommended that you read package.json completely first, and then I will give you a reference project: angular-baidu-map. My source code is written in
es6
, compiled throughwebpack + babel
, and the compiled file is published innpm
. Themain
field points todist/angular-baidu-map.js
(the compiled file).When others are also using
babel
or other compilation environments that support theES6
module specification, they can useimport {ngBaiduMap} from 'angular-baidu-map';
to reference my moduleThis is the usual
babel配置
. I found that it was not there. I filtered thenode_modules
folder. That is to say, the dependencies installed by the npm method will not be compiled by Babel... andimport
is not compiled. It cannot be executed directly...It would be best if the release on npm can be compiled and then released. If it is someone else's project and there is no way to change it, then npm has been downloaded and moved to the project folder and then referenced.
babel or other converted modules see @leftstick’s answer
Native support is a complex topic, please read this article first: https://medium.com/@nodesource/es-modules-and-node-js-hard-choices-2b6995e4d491#.j7lkau8kq