Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Cannot use import statement outside a module #1

Open
cnn007 opened this issue Apr 25, 2023 · 5 comments
Open

SyntaxError: Cannot use import statement outside a module #1

cnn007 opened this issue Apr 25, 2023 · 5 comments

Comments

@cnn007
Copy link

cnn007 commented Apr 25, 2023

use sdk-nodejs-zincsearch/exmaples/index/exists/main.js

`/* Copyright 2022 Zinc Labs Inc. and Contributors
*

  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at
  • http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
    */

var ZincSearchSDK = require('../../../src/index');

let defaultClient = ZincSearchSDK.ApiClient.instance;
// Configure HTTP basic authorization: basicAuth
let basicAuth = defaultClient.authentications['basicAuth'];
basicAuth.username = 'admin';
basicAuth.password = 'Complexpass#123';

let apiInstance = new ZincSearchSDK.Index();
let index = "index_example"; // String | Index
apiInstance.exists(index, (error, data, response) => {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});`

errinfo:
sdk-nodejs-zincsearch/src/index.js:15
import ApiClient from './ApiClient';
^^^^^^

SyntaxError: Cannot use import statement outside a module

==================

@hengfeiyang
Copy link
Collaborator

We published sdk in npmjs, you should use that: https://www.npmjs.com/search?q=zincsearch

@cnn007
Copy link
Author

cnn007 commented Apr 26, 2023

Using this' https://www.npmjs.com/package/zincsearch-sdk' The expression+zincsearch-sdk demo reported an error.
code:

// import ZincSearchSDK from 'zincsearch-sdk'
// const { ZincSearchSDK } = require('zincsearch-sdk')
const ZincSearchSDK = require('zincsearch-sdk')

function test1() {

}

test1()

image

package.json

{
  "name": "zincsearch-demo",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "cookie-parser": "~1.4.4",
    "debug": "~2.6.9",
    "express": "~4.16.1",
    "http-errors": "~1.6.3",
    "morgan": "~1.9.1",
    "mysql2": "^3.2.3",
    "pug": "2.0.0-beta11",
    "sequelize": "^6.31.0",
    "undici": "^5.22.0",
    "zincsearch-sdk": "^0.3.3"
  }
}

@hengfeiyang
Copy link
Collaborator

Yes, it looks can't work with latest nodejs. i will try to fix it. Thanks.

@basaran
Copy link

basaran commented Apr 15, 2024

I think it should be "type": "module" in the package.json, and once this is done, I think it would also require changing the import statements to include ".js" file extensions. That should take care of the module issue. I will try to test it tonight.

@basaran
Copy link

basaran commented Apr 15, 2024

I was able to build the current project with rollup as an ES bundle. Would you like me to send a PR ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants