# Error when using CLI to import workflows

**URL:** <https://community.n8n.io/t/error-when-using-cli-to-import-workflows/49584>\
**Category:** Questions\
**Tags:** cli\
**Created:** [July 3, 2024, 11:17pm UTC](https://community.n8n.io/t/error-when-using-cli-to-import-workflows/49584 "2024-07-03T23:17:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarioGuimaraes](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/marioguimaraes/32/19803_2.png) [@MarioGuimaraes](https://community.n8n.io/u/MarioGuimaraes)\
**Post date:** [July 3, 2024, 11:17pm UTC](https://community.n8n.io/t/error-when-using-cli-to-import-workflows/49584/1 "2024-07-03T23:17:25Z")

</div>

## Describe the problem/error/question

When I use the CLI to import all or a workflow, I get this error

## What is the error message (if any)?

```auto
~ $ n8n import:workflow --input=/files/n8n-workflows/CpDs6GApbWob6kud.json
User settings loaded from: /home/node/.n8n/config
2024-07-03T22:56:52.654Z | debug | Lazy Loading credentials and nodes from n8n-nodes-base "{\n credentials: 356,\n nodes: 453,\n file: 'LoggerProxy.js',\n function: 'exports.debug'\n}"
2024-07-03T22:56:52.669Z | debug | Lazy Loading credentials and nodes from @n8n/n8n-nodes-langchain "{\n credentials: 15,\n nodes: 74,\n file: 'LoggerProxy.js',\n function: 'exports.debug'\n}"
2024-07-03T22:56:52.810Z | debug | [Concurrency Control] Service disabled "{ file: 'concurrency-control.service.js', function: 'log' }"
2024-07-03T22:56:52.892Z | error | An error occurred while importing workflows. See log messages for details. "{ file: 'workflow.js', function: 'catch' }"
2024-07-03T22:56:52.893Z | error | workflows.map is not a function "{ file: 'workflow.js', function: 'catch' }"

~ $ n8n import:workflow --separate --input=/files/n8n-workflows/
User settings loaded from: /home/node/.n8n/config
2024-07-03T22:59:18.830Z | debug | Lazy Loading credentials and nodes from n8n-nodes-base "{\n credentials: 356,\n nodes: 453,\n file: 'LoggerProxy.js',\n function: 'exports.debug'\n}"
2024-07-03T22:59:18.844Z | debug | Lazy Loading credentials and nodes from @n8n/n8n-nodes-langchain "{\n credentials: 15,\n nodes: 74,\n file: 'LoggerProxy.js',\n function: 'exports.debug'\n}"
2024-07-03T22:59:18.976Z | debug | [Concurrency Control] Service disabled "{ file: 'concurrency-control.service.js', function: 'log' }"
2024-07-03T22:59:19.127Z | info | Importing 151 workflows... "{ file: 'workflow.js', function: 'run' }"
2024-07-03T22:59:19.378Z | info | Deactivating workflow "Text To Speech". Remember to activate later. "{ file: 'import.service.js' }"
2024-07-03T22:59:19.394Z | error | An error occurred while importing workflows. See log messages for details. "{ file: 'workflow.js', function: 'catch' }"
2024-07-03T22:59:19.395Z | error | duplicate key value violates unique constraint "idx_812eb05f7451ca757fb98444ce" "{ file: 'workflow.js', function: 'catch' }"

```

The Credential imports works:

```auto
~ $ n8n import:credentials --separate --input=/files/n8n-credentials/
User settings loaded from: /home/node/.n8n/config
2024-07-03T22:55:32.672Z | debug | Lazy Loading credentials and nodes from n8n-nodes-base "{\n credentials: 356,\n nodes: 453,\n file: 'LoggerProxy.js',\n function: 'exports.debug'\n}"
2024-07-03T22:55:32.690Z | debug | Lazy Loading credentials and nodes from @n8n/n8n-nodes-langchain "{\n credentials: 15,\n nodes: 74,\n file: 'LoggerProxy.js',\n function: 'exports.debug'\n}"
2024-07-03T22:55:32.846Z | debug | [Concurrency Control] Service disabled "{ file: 'concurrency-control.service.js', function: 'log' }"
2024-07-03T22:55:33.077Z | info | Successfully imported 26 credentials. "{ file: 'credentials.js', function: 'reportSuccess' }"

```

## Information on your n8n setup

- **n8n version:** 1.48.2
- **Database (default: SQLite):** Postgres
- **n8n EXECUTIONS\_PROCESS setting (default: own, main):** own
- **Running n8n via (Docker, npm, n8n cloud, desktop app):** Docker
- **Operating system:** Linux

---

<div class="post-metadata">

**Author:** ![Ludwig](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ludwig/32/58969_2.png) [@Ludwig](https://community.n8n.io/u/Ludwig)\
**Post date:** [July 4, 2024, 3:59am UTC](https://community.n8n.io/t/error-when-using-cli-to-import-workflows/49584/2 "2024-07-04T03:59:52Z")

</div>

Hi @MarioGuimaraes, thank you for reaching out and being a part of the community!

In what directory are you running your commands?

You might encounter that error if you’re running them outside of your configuration folder.

> [@How to export all my workflows](http://community.n8n.io/t/how-to-export-all-my-workflows/9012/6):
>
> So you’re running n8n directly from the repository? In this case, the binary would be in the packages/cli/bin directory. So you could cd into that directory and run it like .\n8n export:workflow --all on Windows or ./n8n export:workflow --all on Linux/MacOS X.

---

<div class="post-metadata">

**Author:** ![MarioGuimaraes](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/marioguimaraes/32/19803_2.png) [@MarioGuimaraes](https://community.n8n.io/u/MarioGuimaraes)\
**Post date:** [July 4, 2024, 11:11pm UTC](https://community.n8n.io/t/error-when-using-cli-to-import-workflows/49584/3 "2024-07-04T23:11:10Z")

</div>

> [@Ludwig](#):
>
> Hi @MarioGuimaraes, thank you for reaching out and being a part of the community!
> 
> In what directory are you running your commands?
> 
> You might encounter that error if you’re running them outside of your configuration folder.

Hello, @Ludwig  
Thanks for your answer

When I’m executing in /root/.n8n or in another folder, the same error happening

```auto
~/.n8n # ls -lah
total 32K    
drwxr-xr-x 5 root root 4.0K Jul 4 22:42 .
drwx------ 1 root root 4.0K Jul 4 22:56 ..
drwxr-xr-x 2 root root 4.0K Jul 4 22:42 binaryData
-rw-r--r-- 1 root root 54 Jul 4 22:42 config
drwxr-xr-x 2 root root 4.0K Jul 4 22:42 git
-rw-r--r-- 1 root root 2.8K Jul 4 22:43 n8nEventLog.log
drwxr-xr-x 2 root root 4.0K Jul 4 22:42 ssh
~/.n8n # n8n import:workflow --input=/files/n8n-workflows/1MPka8hRy25atJdb.json
User settings loaded from: /root/.n8n/config
An error occurred while importing workflows. See log messages for details.
workflows.map is not a function
~/.n8n # 

```

in root:

```auto
~ # pwd
/root
~ # n8n import:workflow --input=/files/n8n-workflows/1MPka8hRy25atJdb.json
User settings loaded from: /root/.n8n/config
An error occurred while importing workflows. See log messages for details.
workflows.map is not a function

```

---

<div class="post-metadata">

**Author:** ![Ludwig](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ludwig/32/58969_2.png) [@Ludwig](https://community.n8n.io/u/Ludwig)\
**Post date:** [July 5, 2024, 12:06pm UTC](https://community.n8n.io/t/error-when-using-cli-to-import-workflows/49584/4 "2024-07-05T12:06:35Z")

</div>

Are you able to manually import that workflow into your instance? By clicking the “Import Workflow from File” in the triple dot menu at the top right when viewing a workflow.

 ![Screenshot 2024-07-05 at 8.05.41 AM](https://europe1.discourse-cdn.com/n8n/original/3X/0/d/0dedd5ba336f9a438fb86219533e1cd9cada9e64.png)

---

<div class="post-metadata">

**Author:** ![netroy](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/netroy/32/22154_2.png) [@netroy](https://community.n8n.io/u/netroy)\
**Post date:** [July 5, 2024, 3:10pm UTC](https://community.n8n.io/t/error-when-using-cli-to-import-workflows/49584/5 "2024-07-05T15:10:06Z")

</div>

> [@MarioGuimaraes](#):
>
> `workflows.map is not a function`

This implies that `CpDs6GApbWob6kud.json` is a single workflow, and not an array. `--input` without a `--separate` expects a single JSON file with an array of all the workflows. The second command looks correct though. and we should also definitely detect and handle this mistake better.

> [@MarioGuimaraes](#):
>
> `duplicate key value violates unique constraint`

The second command failed because the importing data has tags that already exist in your database, and while we do upserts for workflows and tags, looks like we missed some scenario.

---

<div class="post-metadata">

**Author:** ![MarioGuimaraes](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/marioguimaraes/32/19803_2.png) [@MarioGuimaraes](https://community.n8n.io/u/MarioGuimaraes)\
**Post date:** [July 8, 2024, 4:48am UTC](https://community.n8n.io/t/error-when-using-cli-to-import-workflows/49584/6 "2024-07-08T04:48:17Z")

</div>

I don’t know what’s going on, but now it works

---

<div class="post-metadata">

**Author:** ![despairblue](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/despairblue/32/32053_2.png) [@despairblue](https://community.n8n.io/u/despairblue)\
**Post date:** [July 8, 2024, 5:08pm UTC](https://community.n8n.io/t/error-when-using-cli-to-import-workflows/49584/7 "2024-07-08T17:08:38Z")

</div>

@MarioGuimaraes did you do a full export again?

From reading the code my guess would be that you had multiple workflows in that directory and somehow they ended up having tags that had the same name, but different IDs. That would lead the current import code to try to create multiple tags with the same name which would violate the constraint we have in the db. That’s one way to explain the `duplicate key value violates unique constraint`.

But I’m happy that it works now ❤

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [October 6, 2024, 5:09pm UTC](https://community.n8n.io/t/error-when-using-cli-to-import-workflows/49584/8 "2024-10-06T17:09:31Z")

</div>

Closed on October 6, 2024, 5:09pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
