jbrooksuk / node-summary

Node module that summarizes text using a naive summarization algorithm

Home Page:http://jbrooksuk.github.io/node-summary/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

summary.js import statements causing error

kingychiu opened this issue · comments

The import statements in the summary.js causing error:

import _ from 'lodash'
import Tokenizer from 'sbd'
import request from 'request'
(function (exports, require, module, __filename, __dirname) { import _ from 'lodash'
                                                              ^^^^^^
SyntaxError: Unexpected token import

node version: v6.11.1

commented

Same here node: '7.2.1',

v7.6.0 shows this error as well...

Works fine on v8.5.0

@fungilation Upgraded to 8.5.0, and still getting an error, using "node-summary": "^1.2.0", in my package.json

Curious, try switching to my fork? I don't want some PRs merged to master here so my app is using my fork still, and it works fine for me on latest node. If it works for you too then we know it's something in master recently that went wrong.

I'm on node 8.7.0 - this doesn't work yet without enabling module support and using a .mjs extension. Anyways @jbrooksuk are you open to accepting a pr which builds and publishes the transpiled source?

I'm not sure what's the cause of import issues. I'm on node 8.7 and using in my React Native app without issue. For reference in debugging, this is my package.json:

{
  "name": "APP",
  "version": "0.0.1",
  "private": true,
  "eslintConfig": {
    "parserOptions": {
      "ecmaVersion": 6,
      "sourceType": "module",
      "ecmaFeatures": {
        "jsx": true,
        "experimentalObjectRestSpread": true
      }
    },
    "env": {
      "browser": true,
      "node": true
    },
    "plugins": [
      "react",
      "react-native"
    ],
    "rules": {
      "comma-dangle": [
        2,
        "always-multiline"
      ],
      "semi": [
        2,
        "never"
      ],
      "react-native/no-unused-styles": 2,
      "react-native/split-platform-components": 2
    }
  },
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start"
  },
  "dependencies": {
    "babel-plugin-idx": "^2",
    "he": "^1.1.0",
    "jssha": "^2.3.1",
    "lodash": "^4.17.2",
    "moment-timezone": "^0.5.10",
    "node-summary": "../node-summary",
    "react": "16.0.0-beta.5",
    "react-native": "0.49.3",
    "react-native-blur": "^3.1",
    "react-native-code-push": "5.1.3-beta",
    "react-native-firebase": "^3.0",
    "react-native-fit-image": "^1.4.8",
    "react-native-highlight-words": "smartkarma/react-native-highlight-words",
    "react-native-keep-awake": "envoy/react-native-keep-awake",
    "react-native-linear-gradient": "^2.0.0",
    "react-native-modalbox": "^1.3.8",
    "react-native-notification": "../react-native-notification",
    "react-native-orientation": "^3.0.0",
    "react-native-parallax-scroll-view": "../react-native-parallax-scroll-view",
    "react-native-safari-view": "^2.0.0",
    "react-native-sentry": "^0.28.0",
    "react-native-status-bar-size": "^0.3.2",
    "react-native-swiper": "^1.5.10",
    "react-native-tooltip": "../react-native-tooltip",
    "react-native-tts": "^1.3.0",
    "react-native-vector-icons": "^4.1.1",
    "react-native-webview-bridge": "../react-native-webview-bridge-RN0.40",
    "react-redux": "^5.0.1",
    "redux": "^3.6.0",
    "redux-thunk": "^2.1.0"
  },
  "devDependencies": {
    "redux-logger": "^3.0.6"
  },
  "resolutions": {
    "moment-timezone/moment": "^2.19.0"
  }
}

$ react-native info

Scanning folders for symlinks in [APP_ROOT]/node_modules (37ms)

Environment:
  OS:  macOS Sierra 10.12.6
  Node:  8.7.0
  Yarn:  1.2.1
  npm:  5.4.2
  Watchman:  4.9.0
  Xcode:  Xcode 9.0 Build version 9A235
  Android Studio:  Not Found

Packages: (wanted => installed)
  react: 16.0.0-beta.5 => 16.0.0-beta.5
  react-native: 0.49.3 => 0.49.3

@fungilation this is because you are transpiling the source with babel. It breaks with pure node. Try it in a project that doesn't transpile.

the same problems here

I just tried with the master branch today, and got the same error.

@jbrooksuk would you accept a PR changing to point at the transpiled js?

My workaround is that I created my own local module with rollup.

For anyone interested, as a quick fix I just transpiled it to a local file with a basic webpack config

const path = require('path');
module.exports = {
  mode: "development",
  optimization: {
    minimize: false
  },
  target: 'node',
  entry: './node_modules/node-summary/index.js',
  output: {
    path: path.join(__dirname),
    filename: 'node-summary.js',
    library: 'node-summary',
    libraryTarget: 'commonjs2'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
      },
    ]
  }
}

Save this to webpack.config.js and run webpack it'll save to node-summary.js

You need to ship the transpiled code in the published module rather than the raw code. babel won't transpile code under the node_modules folder by default so it needs to be done by the library publisher before publishing to npm.

let _ = require('lodash')
let Tokenizer = require('sbd')
let request = require('request')

I created a pull request fixing this issue(#50). You can use that instead the main package by using the command (or just wait him fix the issue / or merge the PR):
npm install https://github.com/TroniPM/node-summary