import-js icon indicating copy to clipboard operation
import-js copied to clipboard

CLI running but not adding to file

Open mweber-ak opened this issue 6 years ago • 1 comments

When I try running `importjs fix``` on the specified file from the CLI it outputs the below but doesn't actually change the file. The file has no imports in it.

\Documents\GitHub\platformx\client> importjs fix src/views/Customer.js
{"messages":["Added 3 imports"],"fileContent":"import { Switch } from '@material-ui/core';\nimport { connect } from 'react-redux';\nimport React from 'react';\n\nconst Customer = props => {\r\n  return (\r\n    <Switch>\r\n      <Route\r\n        exact\r\n        path=\"/customer\"\r\n        render={props => <CustomerDisplay customer={props.customer} />}\r\n      />\r\n      <Route\r\n        path=\"/customer/planned\"\r\n        render={props => <CustomerLoadsDisplay customer={props.customer} />}\r\n      />\r\n      <Route\r\n        path=\"/customer/load-history\"\r\n        render={props => <CustomerHistoryDisplay customer={props.customer} />}\r\n      />\r\n      <Route\r\n        path=\"/customer/in-transit\"\r\n        render={props => <CustomerInTransitDisplay customer={props.customer} />}\r\n      />\r\n    </Switch>\r\n  );\r\n};\r\n\r\nconst mapStateToProps = state => ({\r\n  customer: state.customer,\r\n  auth: state.auth,\r\n});\r\n\r\nexport default connect(\r\n  mapStateToProps,\r\n  {}\r\n)(Customer);\r\n","unresolvedImports":{"CustomerDisplay":[{"displayName":"import { CustomerDisplay } from '../components/templates';","importPath":"../components/templates","data":{"importPath":"../components/templates","filePath":"src/components/templates/index.js","isNamedExport":true}},{"displayName":"import CustomerDisplay from '../components/templates/CustomerDisplay';","importPath":"../components/templates/CustomerDisplay","data":{"importPath":"../components/templates/CustomerDisplay","filePath":"./src/components/templates/CustomerDisplay.js","isNamedExport":false}}],"CustomerLoadsDisplay":[{"displayName":"import { CustomerLoadsDisplay } from '../components/templates';","importPath":"../components/templates","data":{"importPath":"../components/templates","filePath":"src/components/templates/index.js","isNamedExport":true}},{"displayName":"import CustomerLoadsDisplay from '../components/templates/CustomerLoadsDisplay';","importPath":"../components/templates/CustomerLoadsDisplay","data":{"importPath":"../components/templates/CustomerLoadsDisplay","filePath":"./src/components/templates/CustomerLoadsDisplay.js","isNamedExport":false}}],"CustomerHistoryDisplay":[{"displayName":"import { CustomerHistoryDisplay } from '../components/templates';","importPath":"../components/templates","data":{"importPath":"../components/templates","filePath":"src/components/templates/index.js","isNamedExport":true}},{"displayName":"import CustomerHistoryDisplay from '../components/templates/CustomerHistoryDisplay';","importPath":"../components/templates/CustomerHistoryDisplay","data":{"importPath":"../components/templates/CustomerHistoryDisplay","filePath":"./src/components/templates/CustomerHistoryDisplay.js","isNamedExport":false}}],"CustomerInTransitDisplay":[{"displayName":"import { CustomerInTransitDisplay } from '../components/templates';","importPath":"../components/templates","data":{"importPath":"../components/templates","filePath":"src/components/templates/index.js","isNamedExport":true}},{"displayName":"import CustomerInTransitDisplay from '../components/templates/CustomerInTransitDisplay';","importPath":"../components/templates/CustomerInTransitDisplay","data":{"importPath":"../components/templates/CustomerInTransitDisplay","filePath":"./src/components/templates/CustomerInTransitDisplay.js","isNamedExport":false}}]}}

My Config

module.exports = {
  excludes: [
    './react-components/**/test/**'
  ],
  environments: ['node'],
  stripFileExtensions: ['.web.js', '.js']
}

mweber-ak avatar Aug 28 '19 23:08 mweber-ak

I tried from the VS-Code Extension and got strange behavior, it would add it for a second until it came to a point where it would ask me which file to import from, if I select an answer it clears all the previous imports.

mweber-ak avatar Aug 28 '19 23:08 mweber-ak

Hi,

Did you manage to get this to work? If not, could you submit the contents of Customer.js so we can try to reproduce on our side?

Thanks

mikabytes avatar Jan 29 '24 07:01 mikabytes

Just realized, importjs fix doesn't actually write to the file. You need to pass the overwrite flag for that behavior. Like this:

importjs fix --overwrite src/views/Customer.js

I'll close this. If you need any more guidance, feel free to reopen it. Thanks.

mikabytes avatar Feb 02 '24 11:02 mikabytes