我正在使用ubuntu 16.04。我已经安装了正确安装的polymer-cli npm install -g polymer-cli
,但是当我输入命令polymer server
时
聚合物发出错误:找不到命令。
答案 0 :(得分:3)
要检查包是否全局安装,您可以查看npm根文件夹。
public class MyBluetoothService {
private static final String TAG = "MY_APP_DEBUG_TAG";
private Handler mHandler; // handler that gets info from Bluetooth service
// Defines several constants used when transmitting messages between the
// service and the UI.
private interface MessageConstants {
public static final int MESSAGE_READ = 0;
public static final int MESSAGE_WRITE = 1;
public static final int MESSAGE_TOAST = 2;
// ... (Add other message types here as needed.)
}
private class ConnectedThread extends Thread {
private final BluetoothSocket mmSocket;
private final InputStream mmInStream;
private final OutputStream mmOutStream;
private byte[] mmBuffer; // mmBuffer store for the stream
public ConnectedThread(BluetoothSocket socket) {
mmSocket = socket;
InputStream tmpIn = null;
OutputStream tmpOut = null;
// Get the input and output streams; using temp objects because
// member streams are final.
try {
tmpIn = socket.getInputStream();
} catch (IOException e) {
Log.e(TAG, "Error occurred when creating input stream", e);
}
try {
tmpOut = socket.getOutputStream();
} catch (IOException e) {
Log.e(TAG, "Error occurred when creating output stream", e);
}
mmInStream = tmpIn;
mmOutStream = tmpOut;
}
public void run() {
mmBuffer = new byte[1024];
int numBytes; // bytes returned from read()
// Keep listening to the InputStream until an exception occurs.
while (true) {
try {
// Read from the InputStream.
numBytes = mmInStream.read(mmBuffer);
// Send the obtained bytes to the UI activity.
Message readMsg = mHandler.obtainMessage(
MessageConstants.MESSAGE_READ, numBytes, -1,
mmBuffer);
readMsg.sendToTarget();
} catch (IOException e) {
Log.d(TAG, "Input stream was disconnected", e);
break;
}
}
}
// Call this from the main activity to send data to the remote device.
public void write(byte[] bytes) {
try {
mmOutStream.write(bytes);
// Share the sent message with the UI activity.
Message writtenMsg = mHandler.obtainMessage(
MessageConstants.MESSAGE_WRITE, -1, -1, mmBuffer);
writtenMsg.sendToTarget();
} catch (IOException e) {
Log.e(TAG, "Error occurred when sending data", e);
// Send a failure message back to the activity.
Message writeErrorMsg =
mHandler.obtainMessage(MessageConstants.MESSAGE_TOAST);
Bundle bundle = new Bundle();
bundle.putString("toast",
"Couldn't send data to the other device");
writeErrorMsg.setData(bundle);
mHandler.sendMessage(writeErrorMsg);
}
}
// Call this method from the main activity to shut down the connection.
public void cancel() {
try {
mmSocket.close();
} catch (IOException e) {
Log.e(TAG, "Could not close the connect socket", e);
}
}
}
}
会显示根文件夹
因此,npm root -g
列出了所有公共安装的软件包。
如果你没有找到聚合物-cli那么你的全局安装就没有成功......如果你在那里找到它但你仍然无法使用它,你可能想尝试重新安装它。
答案 1 :(得分:0)
对我来说,答案是因为节点的bin文件夹未在PATH中定义。
对我来说,解决方法是将其添加到export PATH=
文件的.zshrc
部分,或者,如果不使用ZSH,则将其添加到.bash_profile
。要知道要添加到此PATH
导出中的内容,请运行npm bin -g
。对我而言,输出为/usr/local/Cellar/node/11.14.0_1/bin
。之后,我打开了.zshrc
文件,并将:/usr/local/Cellar/node/11.14.0_1/bin
添加到了PATH
定义中。请注意,:
用于区分新位置。
export PATH="$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin:/usr/local/Cellar/node/11.14.0_1/bin"
祝你好运!
答案 2 :(得分:0)
如果polymer-cli已成功全局全局安装,请更改路径环境变量-向其添加polymer.js的父目录,polymer serve
将起作用。您将在.npm-global/bin